
<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>pymatgen.ext.matproj &#8212; pymatgen 2020.7.3 documentation</title>
    <link rel="stylesheet" href="../../../_static/basic.css" type="text/css" />
    <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />
    <script id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../_static/language_data.js"></script>
    <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33990148-1']);
  _gaq.push(['_trackPageview']);
</script>

  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" accesskey="U">pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.ext.matproj</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
          <div class="body" role="main">
            
  <h1>Source code for pymatgen.ext.matproj</h1><div class="highlight"><pre>
<span></span><span class="c1"># coding: utf-8</span>
<span class="c1"># Copyright (c) Pymatgen Development Team.</span>
<span class="c1"># Distributed under the terms of the MIT License.</span>

<span class="sd">&quot;&quot;&quot;</span>
<span class="sd">This module provides classes to interface with the Materials Project REST</span>
<span class="sd">API v2 to enable the creation of data structures and pymatgen objects using</span>
<span class="sd">Materials Project data.</span>

<span class="sd">To make use of the Materials API, you need to be a registered user of the</span>
<span class="sd">Materials Project, and obtain an API key by going to your dashboard at</span>
<span class="sd">https://www.materialsproject.org/dashboard.</span>
<span class="sd">&quot;&quot;&quot;</span>

<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">itertools</span>
<span class="kn">import</span> <span class="nn">json</span>
<span class="kn">import</span> <span class="nn">platform</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">import</span> <span class="nn">warnings</span>
<span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">sleep</span>
<span class="kn">import</span> <span class="nn">requests</span>
<span class="kn">from</span> <span class="nn">monty.json</span> <span class="kn">import</span> <span class="n">MontyDecoder</span><span class="p">,</span> <span class="n">MontyEncoder</span>

<span class="kn">from</span> <span class="nn">enum</span> <span class="kn">import</span> <span class="n">Enum</span><span class="p">,</span> <span class="n">unique</span>
<span class="kn">from</span> <span class="nn">collections</span> <span class="kn">import</span> <span class="n">defaultdict</span>

<span class="kn">from</span> <span class="nn">pymatgen</span> <span class="kn">import</span> <span class="n">SETTINGS</span><span class="p">,</span> <span class="n">__version__</span> <span class="k">as</span> <span class="n">pmg_version</span>

<span class="kn">from</span> <span class="nn">pymatgen.core.composition</span> <span class="kn">import</span> <span class="n">Composition</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.periodic_table</span> <span class="kn">import</span> <span class="n">Element</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.structure</span> <span class="kn">import</span> <span class="n">Structure</span>
<span class="kn">from</span> <span class="nn">pymatgen.core.surface</span> <span class="kn">import</span> <span class="n">get_symmetrically_equivalent_miller_indices</span>

<span class="kn">from</span> <span class="nn">pymatgen.entries.computed_entries</span> <span class="kn">import</span> <span class="n">ComputedEntry</span><span class="p">,</span> \
    <span class="n">ComputedStructureEntry</span>
<span class="kn">from</span> <span class="nn">pymatgen.entries.compatibility</span> <span class="kn">import</span> <span class="n">MaterialsProjectCompatibility</span><span class="p">,</span> <span class="n">MaterialsProjectAqueousCompatibility</span>
<span class="kn">from</span> <span class="nn">pymatgen.entries.exp_entries</span> <span class="kn">import</span> <span class="n">ExpEntry</span>

<span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>

<span class="kn">from</span> <span class="nn">pymatgen.util.sequence</span> <span class="kn">import</span> <span class="n">get_chunks</span><span class="p">,</span> <span class="n">PBar</span>

<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong, Shreyas Cholia&quot;</span>
<span class="n">__credits__</span> <span class="o">=</span> <span class="s2">&quot;Anubhav Jain&quot;</span>
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2012, The Materials Project&quot;</span>
<span class="n">__version__</span> <span class="o">=</span> <span class="s2">&quot;1.0&quot;</span>
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Shyue Ping Ong&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;shyuep@gmail.com&quot;</span>
<span class="n">__date__</span> <span class="o">=</span> <span class="s2">&quot;Feb 22, 2013&quot;</span>


<div class="viewcode-block" id="TaskType"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.TaskType">[docs]</a><span class="nd">@unique</span>
<span class="k">class</span> <span class="nc">TaskType</span><span class="p">(</span><span class="n">Enum</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;task types available in MP&quot;&quot;&quot;</span>
    <span class="n">GGA_OPT</span> <span class="o">=</span> <span class="s2">&quot;GGA Structure Optimization&quot;</span>
    <span class="n">GGAU_OPT</span> <span class="o">=</span> <span class="s2">&quot;GGA+U Structure Optimization&quot;</span>
    <span class="n">SCAN_OPT</span> <span class="o">=</span> <span class="s2">&quot;SCAN Structure Optimization&quot;</span>
    <span class="n">GGA_LINE</span> <span class="o">=</span> <span class="s2">&quot;GGA NSCF Line&quot;</span>
    <span class="n">GGAU_LINE</span> <span class="o">=</span> <span class="s2">&quot;GGA+U NSCF Line&quot;</span>
    <span class="n">GGA_UNIFORM</span> <span class="o">=</span> <span class="s2">&quot;GGA NSCF Uniform&quot;</span>
    <span class="n">GGAU_UNIFORM</span> <span class="o">=</span> <span class="s2">&quot;GGA+U NSCF Uniform&quot;</span>
    <span class="n">GGA_STATIC</span> <span class="o">=</span> <span class="s2">&quot;GGA Static&quot;</span>
    <span class="n">GGAU_STATIC</span> <span class="o">=</span> <span class="s2">&quot;GGA+U Static&quot;</span>
    <span class="n">GGA_STATIC_DIEL</span> <span class="o">=</span> <span class="s2">&quot;GGA Static Dielectric&quot;</span>
    <span class="n">GGAU_STATIC_DIEL</span> <span class="o">=</span> <span class="s2">&quot;GGA+U Static Dielectric&quot;</span>
    <span class="n">GGA_DEF</span> <span class="o">=</span> <span class="s2">&quot;GGA Deformation&quot;</span>
    <span class="n">GGAU_DEF</span> <span class="o">=</span> <span class="s2">&quot;GGA+U Deformation&quot;</span>
    <span class="n">LDA_STATIC_DIEL</span> <span class="o">=</span> <span class="s2">&quot;LDA Static Dielectric&quot;</span></div>


<div class="viewcode-block" id="MPRester"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester">[docs]</a><span class="k">class</span> <span class="nc">MPRester</span><span class="p">:</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    A class to conveniently interface with the Materials Project REST</span>
<span class="sd">    interface. The recommended way to use MPRester is with the &quot;with&quot; context</span>
<span class="sd">    manager to ensure that sessions are properly closed after usage::</span>

<span class="sd">        with MPRester(&quot;API_KEY&quot;) as m:</span>
<span class="sd">            do_something</span>

<span class="sd">    MPRester uses the &quot;requests&quot; package, which provides for HTTP connection</span>
<span class="sd">    pooling. All connections are made via https for security.</span>

<span class="sd">    For more advanced uses of the Materials API, please consult the API</span>
<span class="sd">    documentation at https://github.com/materialsproject/mapidoc.</span>
<span class="sd">    &quot;&quot;&quot;</span>

    <span class="n">supported_properties</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;energy&quot;</span><span class="p">,</span> <span class="s2">&quot;energy_per_atom&quot;</span><span class="p">,</span> <span class="s2">&quot;volume&quot;</span><span class="p">,</span>
                            <span class="s2">&quot;formation_energy_per_atom&quot;</span><span class="p">,</span> <span class="s2">&quot;nsites&quot;</span><span class="p">,</span>
                            <span class="s2">&quot;unit_cell_formula&quot;</span><span class="p">,</span> <span class="s2">&quot;pretty_formula&quot;</span><span class="p">,</span>
                            <span class="s2">&quot;is_hubbard&quot;</span><span class="p">,</span> <span class="s2">&quot;elements&quot;</span><span class="p">,</span> <span class="s2">&quot;nelements&quot;</span><span class="p">,</span>
                            <span class="s2">&quot;e_above_hull&quot;</span><span class="p">,</span> <span class="s2">&quot;hubbards&quot;</span><span class="p">,</span> <span class="s2">&quot;is_compatible&quot;</span><span class="p">,</span>
                            <span class="s2">&quot;spacegroup&quot;</span><span class="p">,</span> <span class="s2">&quot;task_ids&quot;</span><span class="p">,</span> <span class="s2">&quot;band_gap&quot;</span><span class="p">,</span> <span class="s2">&quot;density&quot;</span><span class="p">,</span>
                            <span class="s2">&quot;icsd_id&quot;</span><span class="p">,</span> <span class="s2">&quot;icsd_ids&quot;</span><span class="p">,</span> <span class="s2">&quot;cif&quot;</span><span class="p">,</span> <span class="s2">&quot;total_magnetization&quot;</span><span class="p">,</span>
                            <span class="s2">&quot;material_id&quot;</span><span class="p">,</span> <span class="s2">&quot;oxide_type&quot;</span><span class="p">,</span> <span class="s2">&quot;tags&quot;</span><span class="p">,</span> <span class="s2">&quot;elasticity&quot;</span><span class="p">)</span>

    <span class="n">supported_task_properties</span> <span class="o">=</span> <span class="p">(</span><span class="s2">&quot;energy&quot;</span><span class="p">,</span> <span class="s2">&quot;energy_per_atom&quot;</span><span class="p">,</span> <span class="s2">&quot;volume&quot;</span><span class="p">,</span>
                                 <span class="s2">&quot;formation_energy_per_atom&quot;</span><span class="p">,</span> <span class="s2">&quot;nsites&quot;</span><span class="p">,</span>
                                 <span class="s2">&quot;unit_cell_formula&quot;</span><span class="p">,</span> <span class="s2">&quot;pretty_formula&quot;</span><span class="p">,</span>
                                 <span class="s2">&quot;is_hubbard&quot;</span><span class="p">,</span>
                                 <span class="s2">&quot;elements&quot;</span><span class="p">,</span> <span class="s2">&quot;nelements&quot;</span><span class="p">,</span> <span class="s2">&quot;e_above_hull&quot;</span><span class="p">,</span>
                                 <span class="s2">&quot;hubbards&quot;</span><span class="p">,</span>
                                 <span class="s2">&quot;is_compatible&quot;</span><span class="p">,</span> <span class="s2">&quot;spacegroup&quot;</span><span class="p">,</span>
                                 <span class="s2">&quot;band_gap&quot;</span><span class="p">,</span> <span class="s2">&quot;density&quot;</span><span class="p">,</span> <span class="s2">&quot;icsd_id&quot;</span><span class="p">,</span> <span class="s2">&quot;cif&quot;</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">api_key</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">endpoint</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">include_user_agent</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Args:</span>
<span class="sd">            api_key (str): A String API key for accessing the MaterialsProject</span>
<span class="sd">                REST interface. Please obtain your API key at</span>
<span class="sd">                https://www.materialsproject.org/dashboard. If this is None,</span>
<span class="sd">                the code will check if there is a &quot;PMG_MAPI_KEY&quot; setting.</span>
<span class="sd">                If so, it will use that environment variable. This makes</span>
<span class="sd">                easier for heavy users to simply add this environment variable to</span>
<span class="sd">                their setups and MPRester can then be called without any arguments.</span>
<span class="sd">            endpoint (str): Url of endpoint to access the MaterialsProject REST</span>
<span class="sd">                interface. Defaults to the standard Materials Project REST</span>
<span class="sd">                address at &quot;https://materialsproject.org/rest/v2&quot;, but</span>
<span class="sd">                can be changed to other urls implementing a similar interface.</span>
<span class="sd">            include_user_agent (bool): If True, will include a user agent with the</span>
<span class="sd">                HTTP request including information on pymatgen and system version</span>
<span class="sd">                making the API request. This helps MP support pymatgen users, and</span>
<span class="sd">                is similar to what most web browsers send with each page request.</span>
<span class="sd">                Set to False to disable the user agent.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">api_key</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">api_key</span> <span class="o">=</span> <span class="n">api_key</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">api_key</span> <span class="o">=</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_MAPI_KEY&quot;</span><span class="p">,</span> <span class="s2">&quot;&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">endpoint</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">preamble</span> <span class="o">=</span> <span class="n">endpoint</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">preamble</span> <span class="o">=</span> <span class="n">SETTINGS</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;PMG_MAPI_ENDPOINT&quot;</span><span class="p">,</span>
                                         <span class="s2">&quot;https://materialsproject.org/rest/v2&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">preamble</span> <span class="o">!=</span> <span class="s2">&quot;https://materialsproject.org/rest/v2&quot;</span><span class="p">:</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="s2">&quot;Non-default endpoint used: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">preamble</span><span class="p">))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">session</span> <span class="o">=</span> <span class="n">requests</span><span class="o">.</span><span class="n">Session</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">headers</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;x-api-key&quot;</span><span class="p">:</span> <span class="bp">self</span><span class="o">.</span><span class="n">api_key</span><span class="p">}</span>
        <span class="k">if</span> <span class="n">include_user_agent</span><span class="p">:</span>
            <span class="n">pymatgen_info</span> <span class="o">=</span> <span class="s2">&quot;pymatgen/&quot;</span> <span class="o">+</span> <span class="n">pmg_version</span>
            <span class="n">python_info</span> <span class="o">=</span> <span class="s2">&quot;Python/</span><span class="si">{}</span><span class="s2">.</span><span class="si">{}</span><span class="s2">.</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="o">.</span><span class="n">major</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="o">.</span><span class="n">minor</span><span class="p">,</span> <span class="n">sys</span><span class="o">.</span><span class="n">version_info</span><span class="o">.</span><span class="n">micro</span><span class="p">)</span>
            <span class="n">platform_info</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">/</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">platform</span><span class="o">.</span><span class="n">system</span><span class="p">(),</span> <span class="n">platform</span><span class="o">.</span><span class="n">release</span><span class="p">())</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">headers</span><span class="p">[</span><span class="s2">&quot;user-agent&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> (</span><span class="si">{}</span><span class="s2"> </span><span class="si">{}</span><span class="s2">)&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                <span class="n">pymatgen_info</span><span class="p">,</span> <span class="n">python_info</span><span class="p">,</span> <span class="n">platform_info</span><span class="p">)</span>

    <span class="k">def</span> <span class="fm">__enter__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Support for &quot;with&quot; context.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span>

    <span class="k">def</span> <span class="fm">__exit__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">exc_type</span><span class="p">,</span> <span class="n">exc_val</span><span class="p">,</span> <span class="n">exc_tb</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Support for &quot;with&quot; context.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>

    <span class="k">def</span> <span class="nf">_make_request</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">sub_url</span><span class="p">,</span> <span class="n">payload</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span>
                      <span class="n">mp_decode</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="n">response</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="n">url</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">preamble</span> <span class="o">+</span> <span class="n">sub_url</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">method</span> <span class="o">==</span> <span class="s2">&quot;POST&quot;</span><span class="p">:</span>
                <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">payload</span><span class="p">,</span> <span class="n">verify</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">params</span><span class="o">=</span><span class="n">payload</span><span class="p">,</span> <span class="n">verify</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="mi">400</span><span class="p">]:</span>
                <span class="k">if</span> <span class="n">mp_decode</span><span class="p">:</span>
                    <span class="n">data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyDecoder</span><span class="p">)</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">data</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;valid_response&quot;</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">data</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;warning&quot;</span><span class="p">):</span>
                        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;warning&quot;</span><span class="p">])</span>
                    <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="s2">&quot;response&quot;</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;error&quot;</span><span class="p">])</span>

            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="s2">&quot;REST query returned with error status code </span><span class="si">{}</span><span class="s2">&quot;</span>
                              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">))</span>

        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="n">msg</span> <span class="o">=</span> <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">. Content: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">),</span> <span class="n">response</span><span class="o">.</span><span class="n">content</span><span class="p">)</span> \
                <span class="k">if</span> <span class="nb">hasattr</span><span class="p">(</span><span class="n">response</span><span class="p">,</span> <span class="s2">&quot;content&quot;</span><span class="p">)</span> <span class="k">else</span> <span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">)</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="n">msg</span><span class="p">)</span>

<div class="viewcode-block" id="MPRester.get_materials_id_from_task_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_materials_id_from_task_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_materials_id_from_task_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">task_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns a new MP materials id from a task id (which can be</span>
<span class="sd">        equivalent to an old materials id)</span>

<span class="sd">        Args:</span>
<span class="sd">            task_id (str): A task id.</span>

<span class="sd">        Returns:</span>
<span class="sd">            materials_id (str)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/mid_from_tid/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">task_id</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_materials_id_references"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_materials_id_references">[docs]</a>    <span class="k">def</span> <span class="nf">get_materials_id_references</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns all references for a materials id.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): A material id.</span>

<span class="sd">        Returns:</span>
<span class="sd">            BibTeX (str)</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/</span><span class="si">%s</span><span class="s2">/refs&quot;</span> <span class="o">%</span> <span class="n">material_id</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_data"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemsys_formula_id</span><span class="p">,</span> <span class="n">data_type</span><span class="o">=</span><span class="s2">&quot;vasp&quot;</span><span class="p">,</span> <span class="n">prop</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Flexible method to get any data using the Materials Project REST</span>
<span class="sd">        interface. Generally used by other methods for more specific queries.</span>

<span class="sd">        Format of REST return is *always* a list of dict (regardless of the</span>
<span class="sd">        number of pieces of data returned. The general format is as follows:</span>

<span class="sd">        [{&quot;material_id&quot;: material_id, &quot;property_name&quot; : value}, ...]</span>

<span class="sd">        This is generally a call to</span>
<span class="sd">        https://www.materialsproject.org/rest/v2/materials/vasp/&lt;prop&gt;.</span>
<span class="sd">        See https://github.com/materialsproject/mapidoc for details.</span>

<span class="sd">        Args:</span>
<span class="sd">            chemsys_formula_id (str): A chemical system (e.g., Li-Fe-O),</span>
<span class="sd">                or formula (e.g., Fe2O3) or materials_id (e.g., mp-1234).</span>
<span class="sd">            data_type (str): Type of data to return. Currently can either be</span>
<span class="sd">                &quot;vasp&quot; or &quot;exp&quot;.</span>
<span class="sd">            prop (str): Property to be obtained. Should be one of the</span>
<span class="sd">                MPRester.supported_task_properties. Leave as empty string for a</span>
<span class="sd">                general list of useful properties.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sub_url</span> <span class="o">=</span> <span class="s2">&quot;/materials/</span><span class="si">%s</span><span class="s2">/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">chemsys_formula_id</span><span class="p">,</span> <span class="n">data_type</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">prop</span><span class="p">:</span>
            <span class="n">sub_url</span> <span class="o">+=</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="n">prop</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="n">sub_url</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_materials_ids"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_materials_ids">[docs]</a>    <span class="k">def</span> <span class="nf">get_materials_ids</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemsys_formula</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get all materials ids for a formula or chemsys.</span>

<span class="sd">        Args:</span>
<span class="sd">            chemsys_formula (str): A chemical system (e.g., Li-Fe-O),</span>
<span class="sd">                or formula (e.g., Fe2O3).</span>

<span class="sd">        Returns:</span>
<span class="sd">            ([str]) List of all materials ids.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/</span><span class="si">%s</span><span class="s2">/mids&quot;</span> <span class="o">%</span> <span class="n">chemsys_formula</span><span class="p">,</span>
                                  <span class="n">mp_decode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_doc"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_doc">[docs]</a>    <span class="k">def</span> <span class="nf">get_doc</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">materials_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get the entire data document for one materials id. Use this judiciously.</span>

<span class="sd">        REST Endpoint: https://www.materialsproject.org/materials/&lt;mp-id&gt;/doc.</span>

<span class="sd">        Args:</span>
<span class="sd">            materials_id (str): E.g., mp-1143 for Al2O3</span>

<span class="sd">        Returns:</span>
<span class="sd">            Dict of json document of all data that is displayed on a materials</span>
<span class="sd">            details page.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/</span><span class="si">%s</span><span class="s2">/doc&quot;</span> <span class="o">%</span> <span class="n">materials_id</span><span class="p">,</span>
                                  <span class="n">mp_decode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_xas_data"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_xas_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_xas_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">,</span> <span class="n">absorbing_element</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get X-ray absorption spectroscopy data for absorbing element in the</span>
<span class="sd">        structure corresponding to a material_id. Only X-ray Absorption Near Edge</span>
<span class="sd">        Structure (XANES) for K-edge is supported.</span>

<span class="sd">        REST Endpoint:</span>
<span class="sd">        https://www.materialsproject.org/materials/&lt;mp-id&gt;/xas/&lt;absorbing_element&gt;.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): E.g., mp-1143 for Al2O3</span>
<span class="sd">            absorbing_element (str): The absorbing element in the corresponding</span>
<span class="sd">                structure. E.g., Al in Al2O3</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">element_list</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span>
                                     <span class="n">prop</span><span class="o">=</span><span class="s2">&quot;elements&quot;</span><span class="p">)[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;elements&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">absorbing_element</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">element_list</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span>
                <span class="s2">&quot;</span><span class="si">{}</span><span class="s2"> element not contained in corresponding structure with &quot;</span>
                <span class="s2">&quot;mp_id: </span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">absorbing_element</span><span class="p">,</span> <span class="n">material_id</span><span class="p">))</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span>
            <span class="s2">&quot;/materials/</span><span class="si">{}</span><span class="s2">/xas/</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span> <span class="n">absorbing_element</span><span class="p">),</span>
            <span class="n">mp_decode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="MPRester.get_task_data"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_task_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_task_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemsys_formula_id</span><span class="p">,</span> <span class="n">prop</span><span class="o">=</span><span class="s2">&quot;&quot;</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Flexible method to get any data using the Materials Project REST</span>
<span class="sd">        interface. Generally used by other methods for more specific queries.</span>
<span class="sd">        Unlike the :func:`get_data`_, this method queries the task collection</span>
<span class="sd">        for specific run information.</span>

<span class="sd">        Format of REST return is *always* a list of dict (regardless of the</span>
<span class="sd">        number of pieces of data returned. The general format is as follows:</span>

<span class="sd">        [{&quot;material_id&quot;: material_id, &quot;property_name&quot; : value}, ...]</span>

<span class="sd">        Args:</span>
<span class="sd">            chemsys_formula_id (str): A chemical system (e.g., Li-Fe-O),</span>
<span class="sd">                or formula (e.g., Fe2O3) or materials_id (e.g., mp-1234).</span>
<span class="sd">            prop (str): Property to be obtained. Should be one of the</span>
<span class="sd">                MPRester.supported_properties. Leave as empty string for a</span>
<span class="sd">                general list of useful properties.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">sub_url</span> <span class="o">=</span> <span class="s2">&quot;/tasks/</span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="n">chemsys_formula_id</span>
        <span class="k">if</span> <span class="n">prop</span><span class="p">:</span>
            <span class="n">sub_url</span> <span class="o">+=</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="n">prop</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="n">sub_url</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_structures"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_structures">[docs]</a>    <span class="k">def</span> <span class="nf">get_structures</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemsys_formula_id</span><span class="p">,</span> <span class="n">final</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a list of Structures corresponding to a chemical system, formula,</span>
<span class="sd">        or materials_id.</span>

<span class="sd">        Args:</span>
<span class="sd">            chemsys_formula_id (str): A chemical system (e.g., Li-Fe-O),</span>
<span class="sd">                or formula (e.g., Fe2O3) or materials_id (e.g., mp-1234).</span>
<span class="sd">            final (bool): Whether to get the final structure, or the initial</span>
<span class="sd">                (pre-relaxation) structure. Defaults to True.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of Structure objects.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">prop</span> <span class="o">=</span> <span class="s2">&quot;final_structure&quot;</span> <span class="k">if</span> <span class="n">final</span> <span class="k">else</span> <span class="s2">&quot;initial_structure&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">chemsys_formula_id</span><span class="p">,</span> <span class="n">prop</span><span class="o">=</span><span class="n">prop</span><span class="p">)</span>
        <span class="k">return</span> <span class="p">[</span><span class="n">d</span><span class="p">[</span><span class="n">prop</span><span class="p">]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">]</span></div>

<div class="viewcode-block" id="MPRester.find_structure"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.find_structure">[docs]</a>    <span class="k">def</span> <span class="nf">find_structure</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">filename_or_structure</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Finds matching structures on the Materials Project site.</span>

<span class="sd">        Args:</span>
<span class="sd">            filename_or_structure: filename or Structure object</span>

<span class="sd">        Returns:</span>
<span class="sd">            A list of matching materials project ids for structure.</span>

<span class="sd">        Raises:</span>
<span class="sd">            MPRestError</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">filename_or_structure</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
                <span class="n">s</span> <span class="o">=</span> <span class="n">Structure</span><span class="o">.</span><span class="n">from_file</span><span class="p">(</span><span class="n">filename_or_structure</span><span class="p">)</span>
            <span class="k">elif</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">filename_or_structure</span><span class="p">,</span> <span class="n">Structure</span><span class="p">):</span>
                <span class="n">s</span> <span class="o">=</span> <span class="n">filename_or_structure</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="s2">&quot;Provide filename or Structure object.&quot;</span><span class="p">)</span>
            <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;structure&#39;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">s</span><span class="o">.</span><span class="n">as_dict</span><span class="p">(),</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyEncoder</span><span class="p">)}</span>
            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">post</span><span class="p">(</span>
                <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">/find_structure&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">preamble</span><span class="p">),</span> <span class="n">data</span><span class="o">=</span><span class="n">payload</span>
            <span class="p">)</span>
            <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="mi">400</span><span class="p">]:</span>
                <span class="n">resp</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyDecoder</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">resp</span><span class="p">[</span><span class="s1">&#39;valid_response&#39;</span><span class="p">]:</span>
                    <span class="k">return</span> <span class="n">resp</span><span class="p">[</span><span class="s1">&#39;response&#39;</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;error&quot;</span><span class="p">])</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="s2">&quot;REST error with status code </span><span class="si">{}</span><span class="s2"> and error </span><span class="si">{}</span><span class="s2">&quot;</span>
                              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">))</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.get_entries"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_entries">[docs]</a>    <span class="k">def</span> <span class="nf">get_entries</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemsys_formula_id_criteria</span><span class="p">,</span> <span class="n">compatible_only</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                    <span class="n">inc_structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">property_data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">conventional_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span> <span class="n">sort_by_e_above_hull</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a list of ComputedEntries or ComputedStructureEntries corresponding</span>
<span class="sd">        to a chemical system, formula, or materials_id or full criteria.</span>

<span class="sd">        Args:</span>
<span class="sd">            chemsys_formula_id_criteria (str/dict): A chemical system</span>
<span class="sd">                (e.g., Li-Fe-O), or formula (e.g., Fe2O3) or materials_id</span>
<span class="sd">                (e.g., mp-1234) or full Mongo-style dict criteria.</span>
<span class="sd">            compatible_only (bool): Whether to return only &quot;compatible&quot;</span>
<span class="sd">                entries. Compatible entries are entries that have been</span>
<span class="sd">                processed using the MaterialsProjectCompatibility class,</span>
<span class="sd">                which performs adjustments to allow mixing of GGA and GGA+U</span>
<span class="sd">                calculations for more accurate phase diagrams and reaction</span>
<span class="sd">                energies.</span>
<span class="sd">            inc_structure (str): If None, entries returned are</span>
<span class="sd">                ComputedEntries. If inc_structure=&quot;initial&quot;,</span>
<span class="sd">                ComputedStructureEntries with initial structures are returned.</span>
<span class="sd">                Otherwise, ComputedStructureEntries with final structures</span>
<span class="sd">                are returned.</span>
<span class="sd">            property_data (list): Specify additional properties to include in</span>
<span class="sd">                entry.data. If None, no data. Should be a subset of</span>
<span class="sd">                supported_properties.</span>
<span class="sd">            conventional_unit_cell (bool): Whether to get the standard</span>
<span class="sd">                conventional unit cell</span>
<span class="sd">            sort_by_e_above_hull (bool): Whether to sort the list of entries by</span>
<span class="sd">                e_above_hull (will query e_above_hull as a property_data if True).</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of ComputedEntry or ComputedStructureEntry objects.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># TODO: This is a very hackish way of doing this. It should be fixed</span>
        <span class="c1"># on the REST end.</span>
        <span class="n">params</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;run_type&quot;</span><span class="p">,</span> <span class="s2">&quot;is_hubbard&quot;</span><span class="p">,</span> <span class="s2">&quot;pseudo_potential&quot;</span><span class="p">,</span> <span class="s2">&quot;hubbards&quot;</span><span class="p">,</span>
                  <span class="s2">&quot;potcar_symbols&quot;</span><span class="p">,</span> <span class="s2">&quot;oxide_type&quot;</span><span class="p">]</span>
        <span class="n">props</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">,</span> <span class="s2">&quot;unit_cell_formula&quot;</span><span class="p">,</span> <span class="s2">&quot;task_id&quot;</span><span class="p">]</span> <span class="o">+</span> <span class="n">params</span>
        <span class="k">if</span> <span class="n">sort_by_e_above_hull</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">property_data</span> <span class="ow">and</span> <span class="s2">&quot;e_above_hull&quot;</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">property_data</span><span class="p">:</span>
                <span class="n">property_data</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;e_above_hull&quot;</span><span class="p">)</span>
            <span class="k">elif</span> <span class="ow">not</span> <span class="n">property_data</span><span class="p">:</span>
                <span class="n">property_data</span> <span class="o">=</span> <span class="p">[</span><span class="s2">&quot;e_above_hull&quot;</span><span class="p">]</span>
        <span class="k">if</span> <span class="n">property_data</span><span class="p">:</span>
            <span class="n">props</span> <span class="o">+=</span> <span class="n">property_data</span>
        <span class="k">if</span> <span class="n">inc_structure</span><span class="p">:</span>
            <span class="k">if</span> <span class="n">inc_structure</span> <span class="o">==</span> <span class="s2">&quot;initial&quot;</span><span class="p">:</span>
                <span class="n">props</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;initial_structure&quot;</span><span class="p">)</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">props</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;structure&quot;</span><span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">chemsys_formula_id_criteria</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="n">criteria</span> <span class="o">=</span> <span class="n">MPRester</span><span class="o">.</span><span class="n">parse_criteria</span><span class="p">(</span><span class="n">chemsys_formula_id_criteria</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">criteria</span> <span class="o">=</span> <span class="n">chemsys_formula_id_criteria</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">criteria</span><span class="p">,</span> <span class="n">props</span><span class="p">)</span>

        <span class="n">entries</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
            <span class="n">d</span><span class="p">[</span><span class="s2">&quot;potcar_symbols&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span>
                <span class="s2">&quot;</span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;pseudo_potential&quot;</span><span class="p">][</span><span class="s2">&quot;functional&quot;</span><span class="p">],</span> <span class="n">l</span><span class="p">)</span>
                <span class="k">for</span> <span class="n">l</span> <span class="ow">in</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;pseudo_potential&quot;</span><span class="p">][</span><span class="s2">&quot;labels&quot;</span><span class="p">]]</span>
            <span class="n">data</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;oxide_type&quot;</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;oxide_type&quot;</span><span class="p">]}</span>
            <span class="k">if</span> <span class="n">property_data</span><span class="p">:</span>
                <span class="n">data</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="n">k</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">property_data</span><span class="p">})</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">inc_structure</span><span class="p">:</span>
                <span class="n">e</span> <span class="o">=</span> <span class="n">ComputedEntry</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;unit_cell_formula&quot;</span><span class="p">],</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">],</span>
                                  <span class="n">parameters</span><span class="o">=</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">params</span><span class="p">},</span>
                                  <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                                  <span class="n">entry_id</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;task_id&quot;</span><span class="p">])</span>

            <span class="k">else</span><span class="p">:</span>
                <span class="n">prim</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;initial_structure&quot;</span><span class="p">]</span> <span class="k">if</span> <span class="n">inc_structure</span> <span class="o">==</span> <span class="s2">&quot;initial&quot;</span> \
                    <span class="k">else</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;structure&quot;</span><span class="p">]</span>
                <span class="k">if</span> <span class="n">conventional_unit_cell</span><span class="p">:</span>
                    <span class="n">s</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">prim</span><span class="p">)</span><span class="o">.</span><span class="n">get_conventional_standard_structure</span><span class="p">()</span>
                    <span class="n">energy</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="o">/</span> <span class="nb">len</span><span class="p">(</span><span class="n">prim</span><span class="p">))</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="n">s</span> <span class="o">=</span> <span class="n">prim</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
                    <span class="n">energy</span> <span class="o">=</span> <span class="n">d</span><span class="p">[</span><span class="s2">&quot;energy&quot;</span><span class="p">]</span>
                <span class="n">e</span> <span class="o">=</span> <span class="n">ComputedStructureEntry</span><span class="p">(</span>
                    <span class="n">s</span><span class="p">,</span> <span class="n">energy</span><span class="p">,</span>
                    <span class="n">parameters</span><span class="o">=</span><span class="p">{</span><span class="n">k</span><span class="p">:</span> <span class="n">d</span><span class="p">[</span><span class="n">k</span><span class="p">]</span> <span class="k">for</span> <span class="n">k</span> <span class="ow">in</span> <span class="n">params</span><span class="p">},</span>
                    <span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">,</span>
                    <span class="n">entry_id</span><span class="o">=</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;task_id&quot;</span><span class="p">])</span>
            <span class="n">entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">e</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">compatible_only</span><span class="p">:</span>
            <span class="kn">from</span> <span class="nn">pymatgen.entries.compatibility</span> <span class="kn">import</span> <span class="n">MaterialsProjectCompatibility</span>
            <span class="n">entries</span> <span class="o">=</span> <span class="n">MaterialsProjectCompatibility</span><span class="p">()</span><span class="o">.</span><span class="n">process_entries</span><span class="p">(</span><span class="n">entries</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">sort_by_e_above_hull</span><span class="p">:</span>
            <span class="n">entries</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">entries</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">entry</span><span class="p">:</span> <span class="n">entry</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;e_above_hull&quot;</span><span class="p">])</span>
        <span class="k">return</span> <span class="n">entries</span></div>

<div class="viewcode-block" id="MPRester.get_pourbaix_entries"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_pourbaix_entries">[docs]</a>    <span class="k">def</span> <span class="nf">get_pourbaix_entries</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">chemsys</span><span class="p">,</span> <span class="n">solid_compat</span><span class="o">=</span><span class="n">MaterialsProjectCompatibility</span><span class="p">()):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        A helper function to get all entries necessary to generate</span>
<span class="sd">        a pourbaix diagram from the rest interface.</span>

<span class="sd">        Args:</span>
<span class="sd">            chemsys ([str]): A list of elements comprising the chemical</span>
<span class="sd">                system, e.g. [&#39;Li&#39;, &#39;Fe&#39;]</span>
<span class="sd">            solid_compat: Compatiblity scheme used to pre-process solid DFT energies prior to applying aqueous</span>
<span class="sd">                energy adjustments. Default: MaterialsProjectCompatibility().</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">pymatgen.analysis.pourbaix_diagram</span> <span class="kn">import</span> <span class="n">PourbaixEntry</span><span class="p">,</span> <span class="n">IonEntry</span>
        <span class="kn">from</span> <span class="nn">pymatgen.analysis.phase_diagram</span> <span class="kn">import</span> <span class="n">PhaseDiagram</span>
        <span class="kn">from</span> <span class="nn">pymatgen.core.ion</span> <span class="kn">import</span> <span class="n">Ion</span>

        <span class="n">pbx_entries</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="c1"># Get ion entries first, because certain ions have reference</span>
        <span class="c1"># solids that aren&#39;t necessarily in the chemsys (Na2SO4)</span>
        <span class="n">url</span> <span class="o">=</span> <span class="s1">&#39;/pourbaix_diagram/reference_data/&#39;</span> <span class="o">+</span> <span class="s1">&#39;-&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">chemsys</span><span class="p">)</span>
        <span class="n">ion_data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="n">url</span><span class="p">)</span>
        <span class="n">ion_ref_comps</span> <span class="o">=</span> <span class="p">[</span><span class="n">Composition</span><span class="p">(</span><span class="n">d</span><span class="p">[</span><span class="s1">&#39;Reference Solid&#39;</span><span class="p">])</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span> <span class="n">ion_data</span><span class="p">]</span>
        <span class="n">ion_ref_elts</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">itertools</span><span class="o">.</span><span class="n">chain</span><span class="o">.</span><span class="n">from_iterable</span><span class="p">(</span>
            <span class="n">i</span><span class="o">.</span><span class="n">elements</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">ion_ref_comps</span><span class="p">))</span>
        <span class="n">ion_ref_entries</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_entries_in_chemsys</span><span class="p">(</span>
            <span class="nb">list</span><span class="p">(</span><span class="nb">set</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">e</span><span class="p">)</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">ion_ref_elts</span><span class="p">]</span> <span class="o">+</span> <span class="p">[</span><span class="s1">&#39;O&#39;</span><span class="p">,</span> <span class="s1">&#39;H&#39;</span><span class="p">])),</span>
            <span class="n">property_data</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;e_above_hull&#39;</span><span class="p">],</span> <span class="n">compatible_only</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>

        <span class="c1"># suppress the warning about supplying the required energies; they will be calculated from the</span>
        <span class="c1"># entries we get from MPRester</span>
        <span class="k">with</span> <span class="n">warnings</span><span class="o">.</span><span class="n">catch_warnings</span><span class="p">():</span>
            <span class="n">warnings</span><span class="o">.</span><span class="n">filterwarnings</span><span class="p">(</span><span class="s2">&quot;ignore&quot;</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s2">&quot;You did not provide the required O2 and H2O energies.&quot;</span><span class="p">)</span>
            <span class="n">compat</span> <span class="o">=</span> <span class="n">MaterialsProjectAqueousCompatibility</span><span class="p">(</span><span class="n">solid_compat</span><span class="o">=</span><span class="n">solid_compat</span><span class="p">)</span>
        <span class="n">ion_ref_entries</span> <span class="o">=</span> <span class="n">compat</span><span class="o">.</span><span class="n">process_entries</span><span class="p">(</span><span class="n">ion_ref_entries</span><span class="p">)</span>
        <span class="n">ion_ref_pd</span> <span class="o">=</span> <span class="n">PhaseDiagram</span><span class="p">(</span><span class="n">ion_ref_entries</span><span class="p">)</span>

        <span class="c1"># position the ion energies relative to most stable reference state</span>
        <span class="k">for</span> <span class="n">n</span><span class="p">,</span> <span class="n">i_d</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">ion_data</span><span class="p">):</span>
            <span class="n">ion</span> <span class="o">=</span> <span class="n">Ion</span><span class="o">.</span><span class="n">from_formula</span><span class="p">(</span><span class="n">i_d</span><span class="p">[</span><span class="s1">&#39;Name&#39;</span><span class="p">])</span>
            <span class="n">refs</span> <span class="o">=</span> <span class="p">[</span><span class="n">e</span> <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">ion_ref_entries</span>
                    <span class="k">if</span> <span class="n">e</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">reduced_formula</span> <span class="o">==</span> <span class="n">i_d</span><span class="p">[</span><span class="s1">&#39;Reference Solid&#39;</span><span class="p">]]</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="n">refs</span><span class="p">:</span>
                <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s2">&quot;Reference solid not contained in entry list&quot;</span><span class="p">)</span>
            <span class="n">stable_ref</span> <span class="o">=</span> <span class="nb">sorted</span><span class="p">(</span><span class="n">refs</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="n">x</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s1">&#39;e_above_hull&#39;</span><span class="p">])[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">rf</span> <span class="o">=</span> <span class="n">stable_ref</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">get_reduced_composition_and_factor</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
            <span class="n">solid_diff</span> <span class="o">=</span> <span class="n">ion_ref_pd</span><span class="o">.</span><span class="n">get_form_energy</span><span class="p">(</span><span class="n">stable_ref</span><span class="p">)</span> <span class="o">-</span> <span class="n">i_d</span><span class="p">[</span><span class="s1">&#39;Reference solid energy&#39;</span><span class="p">]</span> <span class="o">*</span> <span class="n">rf</span>
            <span class="n">elt</span> <span class="o">=</span> <span class="n">i_d</span><span class="p">[</span><span class="s1">&#39;Major_Elements&#39;</span><span class="p">][</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">correction_factor</span> <span class="o">=</span> <span class="n">ion</span><span class="o">.</span><span class="n">composition</span><span class="p">[</span><span class="n">elt</span><span class="p">]</span> <span class="o">/</span> <span class="n">stable_ref</span><span class="o">.</span><span class="n">composition</span><span class="p">[</span><span class="n">elt</span><span class="p">]</span>
            <span class="n">energy</span> <span class="o">=</span> <span class="n">i_d</span><span class="p">[</span><span class="s1">&#39;Energy&#39;</span><span class="p">]</span> <span class="o">+</span> <span class="n">solid_diff</span> <span class="o">*</span> <span class="n">correction_factor</span>
            <span class="n">ion_entry</span> <span class="o">=</span> <span class="n">IonEntry</span><span class="p">(</span><span class="n">ion</span><span class="p">,</span> <span class="n">energy</span><span class="p">)</span>
            <span class="n">pbx_entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">PourbaixEntry</span><span class="p">(</span><span class="n">ion_entry</span><span class="p">,</span> <span class="s1">&#39;ion-</span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">n</span><span class="p">)))</span>

        <span class="c1"># Construct the solid pourbaix entries from filtered ion_ref entries</span>
        <span class="n">extra_elts</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">ion_ref_elts</span><span class="p">)</span> <span class="o">-</span> <span class="p">{</span><span class="n">Element</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">chemsys</span><span class="p">}</span> \
            <span class="o">-</span> <span class="p">{</span><span class="n">Element</span><span class="p">(</span><span class="s1">&#39;H&#39;</span><span class="p">),</span> <span class="n">Element</span><span class="p">(</span><span class="s1">&#39;O&#39;</span><span class="p">)}</span>
        <span class="k">for</span> <span class="n">entry</span> <span class="ow">in</span> <span class="n">ion_ref_entries</span><span class="p">:</span>
            <span class="n">entry_elts</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">entry</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">elements</span><span class="p">)</span>
            <span class="c1"># Ensure no OH chemsys or extraneous elements from ion references</span>
            <span class="k">if</span> <span class="ow">not</span> <span class="p">(</span><span class="n">entry_elts</span> <span class="o">&lt;=</span> <span class="p">{</span><span class="n">Element</span><span class="p">(</span><span class="s1">&#39;H&#39;</span><span class="p">),</span> <span class="n">Element</span><span class="p">(</span><span class="s1">&#39;O&#39;</span><span class="p">)}</span> <span class="ow">or</span>
                    <span class="n">extra_elts</span><span class="o">.</span><span class="n">intersection</span><span class="p">(</span><span class="n">entry_elts</span><span class="p">)):</span>
                <span class="c1"># Create new computed entry</span>
                <span class="n">form_e</span> <span class="o">=</span> <span class="n">ion_ref_pd</span><span class="o">.</span><span class="n">get_form_energy</span><span class="p">(</span><span class="n">entry</span><span class="p">)</span>
                <span class="n">new_entry</span> <span class="o">=</span> <span class="n">ComputedEntry</span><span class="p">(</span><span class="n">entry</span><span class="o">.</span><span class="n">composition</span><span class="p">,</span> <span class="n">form_e</span><span class="p">,</span> <span class="n">entry_id</span><span class="o">=</span><span class="n">entry</span><span class="o">.</span><span class="n">entry_id</span><span class="p">)</span>
                <span class="n">pbx_entry</span> <span class="o">=</span> <span class="n">PourbaixEntry</span><span class="p">(</span><span class="n">new_entry</span><span class="p">)</span>
                <span class="n">pbx_entries</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">pbx_entry</span><span class="p">)</span>

        <span class="k">return</span> <span class="n">pbx_entries</span></div>

<div class="viewcode-block" id="MPRester.get_structure_by_material_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_structure_by_material_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_structure_by_material_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">,</span> <span class="n">final</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                     <span class="n">conventional_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a Structure corresponding to a material_id.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id (a string,</span>
<span class="sd">                e.g., mp-1234).</span>
<span class="sd">            final (bool): Whether to get the final structure, or the initial</span>
<span class="sd">                (pre-relaxation) structure. Defaults to True.</span>
<span class="sd">            conventional_unit_cell (bool): Whether to get the standard</span>
<span class="sd">                conventional unit cell</span>

<span class="sd">        Returns:</span>
<span class="sd">            Structure object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">prop</span> <span class="o">=</span> <span class="s2">&quot;final_structure&quot;</span> <span class="k">if</span> <span class="n">final</span> <span class="k">else</span> <span class="s2">&quot;initial_structure&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span> <span class="n">prop</span><span class="o">=</span><span class="n">prop</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">conventional_unit_cell</span><span class="p">:</span>
            <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">prop</span><span class="p">]</span> <span class="o">=</span> <span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">prop</span><span class="p">])</span><span class="o">.</span> \
                <span class="n">get_conventional_standard_structure</span><span class="p">()</span>
        <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">prop</span><span class="p">]</span></div>

<div class="viewcode-block" id="MPRester.get_entry_by_material_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_entry_by_material_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_entry_by_material_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">,</span> <span class="n">compatible_only</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                 <span class="n">inc_structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">property_data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                 <span class="n">conventional_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a ComputedEntry corresponding to a material_id.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id (a string,</span>
<span class="sd">                e.g., mp-1234).</span>
<span class="sd">            compatible_only (bool): Whether to return only &quot;compatible&quot;</span>
<span class="sd">                entries. Compatible entries are entries that have been</span>
<span class="sd">                processed using the MaterialsProjectCompatibility class,</span>
<span class="sd">                which performs adjustments to allow mixing of GGA and GGA+U</span>
<span class="sd">                calculations for more accurate phase diagrams and reaction</span>
<span class="sd">                energies.</span>
<span class="sd">            inc_structure (str): If None, entries returned are</span>
<span class="sd">                ComputedEntries. If inc_structure=&quot;final&quot;,</span>
<span class="sd">                ComputedStructureEntries with final structures are returned.</span>
<span class="sd">                Otherwise, ComputedStructureEntries with initial structures</span>
<span class="sd">                are returned.</span>
<span class="sd">            property_data (list): Specify additional properties to include in</span>
<span class="sd">                entry.data. If None, no data. Should be a subset of</span>
<span class="sd">                supported_properties.</span>
<span class="sd">            conventional_unit_cell (bool): Whether to get the standard</span>
<span class="sd">                conventional unit cell</span>

<span class="sd">        Returns:</span>
<span class="sd">            ComputedEntry or ComputedStructureEntry object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_entries</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span> <span class="n">compatible_only</span><span class="o">=</span><span class="n">compatible_only</span><span class="p">,</span>
                                <span class="n">inc_structure</span><span class="o">=</span><span class="n">inc_structure</span><span class="p">,</span>
                                <span class="n">property_data</span><span class="o">=</span><span class="n">property_data</span><span class="p">,</span>
                                <span class="n">conventional_unit_cell</span><span class="o">=</span><span class="n">conventional_unit_cell</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span></div>

<div class="viewcode-block" id="MPRester.get_dos_by_material_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_dos_by_material_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_dos_by_material_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a Dos corresponding to a material_id.</span>

<span class="sd">        REST Endpoint: https://www.materialsproject.org/rest/v2/materials/&lt;mp-id&gt;/vasp/dos</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id (a string,</span>
<span class="sd">                e.g., mp-1234).</span>

<span class="sd">        Returns:</span>
<span class="sd">            A Dos object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span> <span class="n">prop</span><span class="o">=</span><span class="s2">&quot;dos&quot;</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="s2">&quot;dos&quot;</span><span class="p">]</span></div>

<div class="viewcode-block" id="MPRester.get_bandstructure_by_material_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_bandstructure_by_material_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_bandstructure_by_material_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">,</span> <span class="n">line_mode</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a BandStructure corresponding to a material_id.</span>

<span class="sd">        REST Endpoint: https://www.materialsproject.org/rest/v2/materials/&lt;mp-id&gt;/vasp/bandstructure or</span>
<span class="sd">        https://www.materialsproject.org/rest/v2/materials/&lt;mp-id&gt;/vasp/bandstructure_uniform</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id.</span>
<span class="sd">            line_mode (bool): If True, fetch a BandStructureSymmLine object</span>
<span class="sd">                (default). If False, return the uniform band structure.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A BandStructure object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">prop</span> <span class="o">=</span> <span class="s2">&quot;bandstructure&quot;</span> <span class="k">if</span> <span class="n">line_mode</span> <span class="k">else</span> <span class="s2">&quot;bandstructure_uniform&quot;</span>
        <span class="n">data</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span> <span class="n">prop</span><span class="o">=</span><span class="n">prop</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">][</span><span class="n">prop</span><span class="p">]</span></div>

<div class="viewcode-block" id="MPRester.get_phonon_dos_by_material_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_phonon_dos_by_material_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_phonon_dos_by_material_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get phonon density of states data corresponding to a material_id.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id.</span>

<span class="sd">        Returns:</span>
<span class="sd">            ﻿CompletePhononDos: A phonon DOS object.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/</span><span class="si">{}</span><span class="s2">/phonondos&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">material_id</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.get_phonon_bandstructure_by_material_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_phonon_bandstructure_by_material_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_phonon_bandstructure_by_material_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get phonon dispersion data corresponding to a material_id.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id.</span>

<span class="sd">        Returns:</span>
<span class="sd">            PhononBandStructureSymmLine: A phonon band structure.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/</span><span class="si">{}</span><span class="s2">/phononbs&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">material_id</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.get_phonon_ddb_by_material_id"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_phonon_ddb_by_material_id">[docs]</a>    <span class="k">def</span> <span class="nf">get_phonon_ddb_by_material_id</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get ABINIT Derivative Data Base (DDB) output for phonon calculations.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id.</span>

<span class="sd">        Returns:</span>
<span class="sd">            str: ABINIT DDB file as a string.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/</span><span class="si">{}</span><span class="s2">/abinit_ddb&quot;</span>
                                  <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">material_id</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.get_entries_in_chemsys"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_entries_in_chemsys">[docs]</a>    <span class="k">def</span> <span class="nf">get_entries_in_chemsys</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">elements</span><span class="p">,</span> <span class="n">compatible_only</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                               <span class="n">inc_structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">property_data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                               <span class="n">conventional_unit_cell</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Helper method to get a list of ComputedEntries in a chemical system.</span>
<span class="sd">        For example, elements = [&quot;Li&quot;, &quot;Fe&quot;, &quot;O&quot;] will return a list of all</span>
<span class="sd">        entries in the Li-Fe-O chemical system, i.e., all LixOy,</span>
<span class="sd">        FexOy, LixFey, LixFeyOz, Li, Fe and O phases. Extremely useful for</span>
<span class="sd">        creating phase diagrams of entire chemical systems.</span>

<span class="sd">        Args:</span>
<span class="sd">            elements (str or [str]): Chemical system string comprising element</span>
<span class="sd">                symbols separated by dashes, e.g., &quot;Li-Fe-O&quot; or List of element</span>
<span class="sd">                symbols, e.g., [&quot;Li&quot;, &quot;Fe&quot;, &quot;O&quot;].</span>
<span class="sd">            compatible_only (bool): Whether to return only &quot;compatible&quot;</span>
<span class="sd">                entries. Compatible entries are entries that have been</span>
<span class="sd">                processed using the MaterialsProjectCompatibility class,</span>
<span class="sd">                which performs adjustments to allow mixing of GGA and GGA+U</span>
<span class="sd">                calculations for more accurate phase diagrams and reaction</span>
<span class="sd">                energies.</span>
<span class="sd">            inc_structure (str): If None, entries returned are</span>
<span class="sd">                ComputedEntries. If inc_structure=&quot;final&quot;,</span>
<span class="sd">                ComputedStructureEntries with final structures are returned.</span>
<span class="sd">                Otherwise, ComputedStructureEntries with initial structures</span>
<span class="sd">                are returned.</span>
<span class="sd">            property_data (list): Specify additional properties to include in</span>
<span class="sd">                entry.data. If None, no data. Should be a subset of</span>
<span class="sd">                supported_properties.</span>
<span class="sd">            conventional_unit_cell (bool): Whether to get the standard</span>
<span class="sd">                conventional unit cell</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of ComputedEntries.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">elements</span><span class="p">,</span> <span class="nb">str</span><span class="p">):</span>
            <span class="n">elements</span> <span class="o">=</span> <span class="n">elements</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="p">)</span>

        <span class="n">all_chemsyses</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">elements</span><span class="p">)):</span>
            <span class="k">for</span> <span class="n">els</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">combinations</span><span class="p">(</span><span class="n">elements</span><span class="p">,</span> <span class="n">i</span> <span class="o">+</span> <span class="mi">1</span><span class="p">):</span>
                <span class="n">all_chemsyses</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s1">&#39;-&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">els</span><span class="p">)))</span>

        <span class="n">entries</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_entries</span><span class="p">({</span><span class="s2">&quot;chemsys&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;$in&quot;</span><span class="p">:</span> <span class="n">all_chemsyses</span><span class="p">}},</span>
                                   <span class="n">compatible_only</span><span class="o">=</span><span class="n">compatible_only</span><span class="p">,</span>
                                   <span class="n">inc_structure</span><span class="o">=</span><span class="n">inc_structure</span><span class="p">,</span>
                                   <span class="n">property_data</span><span class="o">=</span><span class="n">property_data</span><span class="p">,</span>
                                   <span class="n">conventional_unit_cell</span><span class="o">=</span><span class="n">conventional_unit_cell</span><span class="p">)</span>
        <span class="k">return</span> <span class="n">entries</span></div>

<div class="viewcode-block" id="MPRester.get_exp_thermo_data"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_exp_thermo_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_exp_thermo_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">formula</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a list of ThermoData objects associated with a formula using the</span>
<span class="sd">        Materials Project REST interface.</span>

<span class="sd">        Args:</span>
<span class="sd">            formula (str): A formula to search for.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of ThermoData objects.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_data</span><span class="p">(</span><span class="n">formula</span><span class="p">,</span> <span class="n">data_type</span><span class="o">=</span><span class="s2">&quot;exp&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_exp_entry"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_exp_entry">[docs]</a>    <span class="k">def</span> <span class="nf">get_exp_entry</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">formula</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns an ExpEntry object, which is the experimental equivalent of a</span>
<span class="sd">        ComputedEntry and can be used for analyses using experimental data.</span>

<span class="sd">        Args:</span>
<span class="sd">            formula (str): A formula to search for.</span>

<span class="sd">        Returns:</span>
<span class="sd">            An ExpEntry object.</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="n">ExpEntry</span><span class="p">(</span><span class="n">Composition</span><span class="p">(</span><span class="n">formula</span><span class="p">),</span>
                        <span class="bp">self</span><span class="o">.</span><span class="n">get_exp_thermo_data</span><span class="p">(</span><span class="n">formula</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.query"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.query">[docs]</a>    <span class="k">def</span> <span class="nf">query</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">criteria</span><span class="p">,</span> <span class="n">properties</span><span class="p">,</span> <span class="n">chunk_size</span><span class="o">=</span><span class="mi">500</span><span class="p">,</span> <span class="n">max_tries_per_chunk</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
              <span class="n">mp_decode</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
        <span class="sa">r</span><span class="sd">&quot;&quot;&quot;</span>

<span class="sd">        Performs an advanced query using MongoDB-like syntax for directly</span>
<span class="sd">        querying the Materials Project database. This allows one to perform</span>
<span class="sd">        queries which are otherwise too cumbersome to perform using the standard</span>
<span class="sd">        convenience methods.</span>

<span class="sd">        Please consult the Materials API documentation at</span>
<span class="sd">        https://github.com/materialsproject/mapidoc, which provides a</span>
<span class="sd">        comprehensive explanation of the document schema used in the Materials</span>
<span class="sd">        Project (supported criteria and properties) and guidance on how best to</span>
<span class="sd">        query for the relevant information you need.</span>

<span class="sd">        For queries that request data on more than CHUNK_SIZE materials at once,</span>
<span class="sd">        this method will chunk a query by first retrieving a list of material</span>
<span class="sd">        IDs that satisfy CRITERIA, and then merging the criteria with a</span>
<span class="sd">        restriction to one chunk of materials at a time of size CHUNK_SIZE. You</span>
<span class="sd">        can opt out of this behavior by setting CHUNK_SIZE=0. To guard against</span>
<span class="sd">        intermittent server errors in the case of many chunks per query,</span>
<span class="sd">        possibly-transient server errors will result in re-trying a give chunk</span>
<span class="sd">        up to MAX_TRIES_PER_CHUNK times.</span>

<span class="sd">        Args:</span>
<span class="sd">            criteria (str/dict): Criteria of the query as a string or</span>
<span class="sd">                mongo-style dict.</span>

<span class="sd">                If string, it supports a powerful but simple string criteria.</span>
<span class="sd">                E.g., &quot;Fe2O3&quot; means search for materials with reduced_formula</span>
<span class="sd">                Fe2O3. Wild cards are also supported. E.g., &quot;\\*2O&quot; means get</span>
<span class="sd">                all materials whose formula can be formed as \\*2O, e.g.,</span>
<span class="sd">                Li2O, K2O, etc.</span>

<span class="sd">                Other syntax examples:</span>
<span class="sd">                mp-1234: Interpreted as a Materials ID.</span>
<span class="sd">                Fe2O3 or *2O3: Interpreted as reduced formulas.</span>
<span class="sd">                Li-Fe-O or *-Fe-O: Interpreted as chemical systems.</span>

<span class="sd">                You can mix and match with spaces, which are interpreted as</span>
<span class="sd">                &quot;OR&quot;. E.g. &quot;mp-1234 FeO&quot; means query for all compounds with</span>
<span class="sd">                reduced formula FeO or with materials_id mp-1234.</span>

<span class="sd">                Using a full dict syntax, even more powerful queries can be</span>
<span class="sd">                constructed. For example, {&quot;elements&quot;:{&quot;$in&quot;:[&quot;Li&quot;,</span>
<span class="sd">                &quot;Na&quot;, &quot;K&quot;], &quot;$all&quot;: [&quot;O&quot;]}, &quot;nelements&quot;:2} selects all Li, Na</span>
<span class="sd">                and K oxides. {&quot;band_gap&quot;: {&quot;$gt&quot;: 1}} selects all materials</span>
<span class="sd">                with band gaps greater than 1 eV.</span>
<span class="sd">            properties (list): Properties to request for as a list. For</span>
<span class="sd">                example, [&quot;formula&quot;, &quot;formation_energy_per_atom&quot;] returns</span>
<span class="sd">                the formula and formation energy per atom.</span>
<span class="sd">            chunk_size (int): Number of materials for which to fetch data at a</span>
<span class="sd">                time. More data-intensive properties may require smaller chunk</span>
<span class="sd">                sizes. Use chunk_size=0 to force no chunking -- this is useful</span>
<span class="sd">                when fetching only properties such as &#39;material_id&#39;.</span>
<span class="sd">            max_tries_per_chunk (int): How many times to re-try fetching a given</span>
<span class="sd">                chunk when the server gives a 5xx error (e.g. a timeout error).</span>
<span class="sd">            mp_decode (bool): Whether to do a decoding to a Pymatgen object</span>
<span class="sd">                where possible. In some cases, it might be useful to just get</span>
<span class="sd">                the raw python dict, i.e., set to False.</span>

<span class="sd">        Returns:</span>
<span class="sd">            List of results. E.g.,</span>
<span class="sd">            [{u&#39;formula&#39;: {u&#39;O&#39;: 1, u&#39;Li&#39;: 2.0}},</span>
<span class="sd">            {u&#39;formula&#39;: {u&#39;Na&#39;: 2.0, u&#39;O&#39;: 2.0}},</span>
<span class="sd">            {u&#39;formula&#39;: {u&#39;K&#39;: 1, u&#39;O&#39;: 3.0}},</span>
<span class="sd">            ...]</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">criteria</span><span class="p">,</span> <span class="nb">dict</span><span class="p">):</span>
            <span class="n">criteria</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parse_criteria</span><span class="p">(</span><span class="n">criteria</span><span class="p">)</span>
        <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;criteria&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">criteria</span><span class="p">),</span>
                   <span class="s2">&quot;properties&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">properties</span><span class="p">)}</span>
        <span class="k">if</span> <span class="n">chunk_size</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span>
                <span class="s2">&quot;/query&quot;</span><span class="p">,</span> <span class="n">payload</span><span class="o">=</span><span class="n">payload</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s2">&quot;POST&quot;</span><span class="p">,</span> <span class="n">mp_decode</span><span class="o">=</span><span class="n">mp_decode</span><span class="p">)</span>

        <span class="n">count_payload</span> <span class="o">=</span> <span class="n">payload</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">count_payload</span><span class="p">[</span><span class="s2">&quot;options&quot;</span><span class="p">]</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">({</span><span class="s2">&quot;count_only&quot;</span><span class="p">:</span> <span class="kc">True</span><span class="p">})</span>
        <span class="n">num_results</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span>
            <span class="s2">&quot;/query&quot;</span><span class="p">,</span> <span class="n">payload</span><span class="o">=</span><span class="n">count_payload</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s2">&quot;POST&quot;</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">num_results</span> <span class="o">&lt;=</span> <span class="n">chunk_size</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span>
                <span class="s2">&quot;/query&quot;</span><span class="p">,</span> <span class="n">payload</span><span class="o">=</span><span class="n">payload</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s2">&quot;POST&quot;</span><span class="p">,</span> <span class="n">mp_decode</span><span class="o">=</span><span class="n">mp_decode</span><span class="p">)</span>

        <span class="n">data</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">mids</span> <span class="o">=</span> <span class="p">[</span><span class="n">d</span><span class="p">[</span><span class="s2">&quot;material_id&quot;</span><span class="p">]</span> <span class="k">for</span> <span class="n">d</span> <span class="ow">in</span>
                <span class="bp">self</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">criteria</span><span class="p">,</span> <span class="p">[</span><span class="s2">&quot;material_id&quot;</span><span class="p">],</span> <span class="n">chunk_size</span><span class="o">=</span><span class="mi">0</span><span class="p">)]</span>
        <span class="n">chunks</span> <span class="o">=</span> <span class="n">get_chunks</span><span class="p">(</span><span class="n">mids</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">chunk_size</span><span class="p">)</span>
        <span class="n">progress_bar</span> <span class="o">=</span> <span class="n">PBar</span><span class="p">(</span><span class="n">total</span><span class="o">=</span><span class="nb">len</span><span class="p">(</span><span class="n">mids</span><span class="p">))</span>
        <span class="k">for</span> <span class="n">chunk</span> <span class="ow">in</span> <span class="n">chunks</span><span class="p">:</span>
            <span class="n">chunk_criteria</span> <span class="o">=</span> <span class="n">criteria</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
            <span class="n">chunk_criteria</span><span class="o">.</span><span class="n">update</span><span class="p">({</span><span class="s2">&quot;material_id&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;$in&quot;</span><span class="p">:</span> <span class="n">chunk</span><span class="p">}})</span>
            <span class="n">num_tries</span> <span class="o">=</span> <span class="mi">0</span>
            <span class="k">while</span> <span class="n">num_tries</span> <span class="o">&lt;</span> <span class="n">max_tries_per_chunk</span><span class="p">:</span>
                <span class="k">try</span><span class="p">:</span>
                    <span class="n">data</span><span class="o">.</span><span class="n">extend</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">query</span><span class="p">(</span><span class="n">chunk_criteria</span><span class="p">,</span> <span class="n">properties</span><span class="p">,</span>
                                           <span class="n">chunk_size</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">mp_decode</span><span class="o">=</span><span class="n">mp_decode</span><span class="p">))</span>
                    <span class="k">break</span>
                <span class="k">except</span> <span class="n">MPRestError</span> <span class="k">as</span> <span class="n">e</span><span class="p">:</span>
                    <span class="n">match</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">search</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;error status code (\d+)&quot;</span><span class="p">,</span> <span class="n">e</span><span class="o">.</span><span class="n">message</span><span class="p">)</span>
                    <span class="k">if</span> <span class="n">match</span><span class="p">:</span>
                        <span class="k">if</span> <span class="ow">not</span> <span class="n">match</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">startswith</span><span class="p">(</span><span class="s2">&quot;5&quot;</span><span class="p">):</span>
                            <span class="k">raise</span> <span class="n">e</span>
                        <span class="k">else</span><span class="p">:</span>  <span class="c1"># 5xx error. Try again</span>
                            <span class="n">num_tries</span> <span class="o">+=</span> <span class="mi">1</span>
                            <span class="nb">print</span><span class="p">(</span>
                                <span class="s2">&quot;Unknown server error. Trying again in five &quot;</span>
                                <span class="s2">&quot;seconds (will try at most </span><span class="si">{}</span><span class="s2"> times)...&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span>
                                    <span class="n">max_tries_per_chunk</span><span class="p">))</span>
                            <span class="n">sleep</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>
            <span class="n">progress_bar</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">chunk</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">data</span></div>

<div class="viewcode-block" id="MPRester.submit_structures"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.submit_structures">[docs]</a>    <span class="k">def</span> <span class="nf">submit_structures</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">structures</span><span class="p">,</span> <span class="n">authors</span><span class="p">,</span> <span class="n">projects</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                          <span class="n">references</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">remarks</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                          <span class="n">histories</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">created_at</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Submits a list of structures to the Materials Project as SNL files.</span>
<span class="sd">        The argument list mirrors the arguments for the StructureNL object,</span>
<span class="sd">        except that a list of structures with the same metadata is used as an</span>
<span class="sd">        input.</span>

<span class="sd">        .. note::</span>

<span class="sd">            As of now, this MP REST feature is open only to a select group of</span>
<span class="sd">            users. Opening up submissions to all users is being planned for</span>
<span class="sd">            the future.</span>

<span class="sd">        Args:</span>
<span class="sd">            structures: A list of Structure objects</span>
<span class="sd">            authors (list): List of {&quot;name&quot;:&#39;&#39;, &quot;email&quot;:&#39;&#39;} dicts,</span>
<span class="sd">                *list* of Strings as &#39;John Doe &lt;johndoe@gmail.com&gt;&#39;,</span>
<span class="sd">                or a single String with commas separating authors</span>
<span class="sd">            projects ([str]): List of Strings [&#39;Project A&#39;, &#39;Project B&#39;].</span>
<span class="sd">                This applies to all structures.</span>
<span class="sd">            references (str): A String in BibTeX format. Again, this applies to</span>
<span class="sd">                all structures.</span>
<span class="sd">            remarks ([str]): List of Strings [&#39;Remark A&#39;, &#39;Remark B&#39;]</span>
<span class="sd">            data ([dict]): A list of free form dict. Namespaced at the root</span>
<span class="sd">                level with an underscore, e.g. {&quot;_materialsproject&quot;:&lt;custom</span>
<span class="sd">                data&gt;}. The length of data should be the same as the list of</span>
<span class="sd">                structures if not None.</span>
<span class="sd">            histories: List of list of dicts - [[{&#39;name&#39;:&#39;&#39;, &#39;url&#39;:&#39;&#39;,</span>
<span class="sd">                &#39;description&#39;:{}}], ...] The length of histories should be the</span>
<span class="sd">                same as the list of structures if not None.</span>
<span class="sd">            created_at (datetime): A datetime object</span>

<span class="sd">        Returns:</span>
<span class="sd">            A list of inserted submission ids.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">pymatgen.util.provenance</span> <span class="kn">import</span> <span class="n">StructureNL</span>
        <span class="n">snl_list</span> <span class="o">=</span> <span class="n">StructureNL</span><span class="o">.</span><span class="n">from_structures</span><span class="p">(</span><span class="n">structures</span><span class="p">,</span> <span class="n">authors</span><span class="p">,</span> <span class="n">projects</span><span class="p">,</span>
                                               <span class="n">references</span><span class="p">,</span> <span class="n">remarks</span><span class="p">,</span> <span class="n">data</span><span class="p">,</span>
                                               <span class="n">histories</span><span class="p">,</span> <span class="n">created_at</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">submit_snl</span><span class="p">(</span><span class="n">snl_list</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.submit_snl"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.submit_snl">[docs]</a>    <span class="k">def</span> <span class="nf">submit_snl</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">snl</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Submits a list of StructureNL to the Materials Project site.</span>

<span class="sd">        .. note::</span>

<span class="sd">            As of now, this MP REST feature is open only to a select group of</span>
<span class="sd">            users. Opening up submissions to all users is being planned for</span>
<span class="sd">            the future.</span>

<span class="sd">        Args:</span>
<span class="sd">            snl (StructureNL/[StructureNL]): A single StructureNL, or a list</span>
<span class="sd">            of StructureNL objects</span>

<span class="sd">        Returns:</span>
<span class="sd">            A list of inserted submission ids.</span>

<span class="sd">        Raises:</span>
<span class="sd">            MPRestError</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">snl</span> <span class="o">=</span> <span class="n">snl</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">snl</span><span class="p">,</span> <span class="nb">list</span><span class="p">)</span> <span class="k">else</span> <span class="p">[</span><span class="n">snl</span><span class="p">]</span>
            <span class="n">jsondata</span> <span class="o">=</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">snl</span><span class="p">]</span>
            <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;snl&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">jsondata</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyEncoder</span><span class="p">)}</span>
            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">/snl/submit&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">preamble</span><span class="p">),</span>
                                         <span class="n">data</span><span class="o">=</span><span class="n">payload</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="mi">400</span><span class="p">]:</span>
                <span class="n">resp</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyDecoder</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">resp</span><span class="p">[</span><span class="s2">&quot;valid_response&quot;</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">resp</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;warning&quot;</span><span class="p">):</span>
                        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;warning&quot;</span><span class="p">])</span>
                    <span class="k">return</span> <span class="n">resp</span><span class="p">[</span><span class="s1">&#39;inserted_ids&#39;</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;error&quot;</span><span class="p">])</span>

            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="s2">&quot;REST error with status code </span><span class="si">{}</span><span class="s2"> and error </span><span class="si">{}</span><span class="s2">&quot;</span>
                              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">))</span>

        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.delete_snl"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.delete_snl">[docs]</a>    <span class="k">def</span> <span class="nf">delete_snl</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">snl_ids</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Delete earlier submitted SNLs.</span>

<span class="sd">        .. note::</span>

<span class="sd">            As of now, this MP REST feature is open only to a select group of</span>
<span class="sd">            users. Opening up submissions to all users is being planned for</span>
<span class="sd">            the future.</span>

<span class="sd">        Args:</span>
<span class="sd">            snl_ids: List of SNL ids.</span>

<span class="sd">        Raises:</span>
<span class="sd">            MPRestError</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;ids&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">snl_ids</span><span class="p">)}</span>
            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">post</span><span class="p">(</span>
                <span class="s2">&quot;</span><span class="si">{}</span><span class="s2">/snl/delete&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">preamble</span><span class="p">),</span> <span class="n">data</span><span class="o">=</span><span class="n">payload</span><span class="p">)</span>

            <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="mi">400</span><span class="p">]:</span>
                <span class="n">resp</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyDecoder</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">resp</span><span class="p">[</span><span class="s2">&quot;valid_response&quot;</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">resp</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;warning&quot;</span><span class="p">):</span>
                        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;warning&quot;</span><span class="p">])</span>
                    <span class="k">return</span> <span class="n">resp</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;error&quot;</span><span class="p">])</span>

            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="s2">&quot;REST error with status code </span><span class="si">{}</span><span class="s2"> and error </span><span class="si">{}</span><span class="s2">&quot;</span>
                              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">))</span>

        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.query_snl"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.query_snl">[docs]</a>    <span class="k">def</span> <span class="nf">query_snl</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">criteria</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Query for submitted SNLs.</span>

<span class="sd">        .. note::</span>

<span class="sd">            As of now, this MP REST feature is open only to a select group of</span>
<span class="sd">            users. Opening up submissions to all users is being planned for</span>
<span class="sd">            the future.</span>

<span class="sd">        Args:</span>
<span class="sd">            criteria (dict): Query criteria.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A dict, with a list of submitted SNLs in the &quot;response&quot; key.</span>

<span class="sd">        Raises:</span>
<span class="sd">            MPRestError</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;criteria&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">criteria</span><span class="p">)}</span>
            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">/snl/query&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">preamble</span><span class="p">),</span>
                                         <span class="n">data</span><span class="o">=</span><span class="n">payload</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="mi">400</span><span class="p">]:</span>
                <span class="n">resp</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">resp</span><span class="p">[</span><span class="s2">&quot;valid_response&quot;</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">resp</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;warning&quot;</span><span class="p">):</span>
                        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;warning&quot;</span><span class="p">])</span>
                    <span class="k">return</span> <span class="n">resp</span><span class="p">[</span><span class="s2">&quot;response&quot;</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;error&quot;</span><span class="p">])</span>

            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="s2">&quot;REST error with status code </span><span class="si">{}</span><span class="s2"> and error </span><span class="si">{}</span><span class="s2">&quot;</span>
                              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">))</span>

        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.submit_vasp_directory"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.submit_vasp_directory">[docs]</a>    <span class="k">def</span> <span class="nf">submit_vasp_directory</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">rootdir</span><span class="p">,</span> <span class="n">authors</span><span class="p">,</span> <span class="n">projects</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                              <span class="n">references</span><span class="o">=</span><span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">remarks</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">master_data</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                              <span class="n">master_history</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">created_at</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                              <span class="n">ncpus</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Assimilates all vasp run directories beneath a particular</span>
<span class="sd">        directory using BorgQueen to obtain structures, and then submits thhem</span>
<span class="sd">        to the Materials Project as SNL files. VASP related meta data like</span>
<span class="sd">        initial structure and final energies are automatically incorporated.</span>

<span class="sd">        .. note::</span>

<span class="sd">            As of now, this MP REST feature is open only to a select group of</span>
<span class="sd">            users. Opening up submissions to all users is being planned for</span>
<span class="sd">            the future.</span>

<span class="sd">        Args:</span>
<span class="sd">            rootdir (str): Rootdir to start assimilating VASP runs from.</span>
<span class="sd">            authors: *List* of {&quot;name&quot;:&#39;&#39;, &quot;email&quot;:&#39;&#39;} dicts,</span>
<span class="sd">                *list* of Strings as &#39;John Doe &lt;johndoe@gmail.com&gt;&#39;,</span>
<span class="sd">                or a single String with commas separating authors. The same</span>
<span class="sd">                list of authors should apply to all runs.</span>
<span class="sd">            projects ([str]): List of Strings [&#39;Project A&#39;, &#39;Project B&#39;].</span>
<span class="sd">                This applies to all structures.</span>
<span class="sd">            references (str): A String in BibTeX format. Again, this applies to</span>
<span class="sd">                all structures.</span>
<span class="sd">            remarks ([str]): List of Strings [&#39;Remark A&#39;, &#39;Remark B&#39;]</span>
<span class="sd">            master_data (dict): A free form dict. Namespaced at the root</span>
<span class="sd">                level with an underscore, e.g. {&quot;_materialsproject&quot;:&lt;custom</span>
<span class="sd">                data&gt;}. This data is added to all structures detected in the</span>
<span class="sd">                directory, in addition to other vasp data on a per structure</span>
<span class="sd">                basis.</span>
<span class="sd">            master_history: A master history to be added to all entries.</span>
<span class="sd">            created_at (datetime): A datetime object</span>
<span class="sd">            ncpus (int): Number of cpus to use in using BorgQueen to</span>
<span class="sd">                assimilate. Defaults to None, which means serial.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">pymatgen.apps.borg.hive</span> <span class="kn">import</span> <span class="n">VaspToComputedEntryDrone</span>
        <span class="kn">from</span> <span class="nn">pymatgen.apps.borg.queen</span> <span class="kn">import</span> <span class="n">BorgQueen</span>
        <span class="n">drone</span> <span class="o">=</span> <span class="n">VaspToComputedEntryDrone</span><span class="p">(</span><span class="n">inc_structure</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                                         <span class="n">data</span><span class="o">=</span><span class="p">[</span><span class="s2">&quot;filename&quot;</span><span class="p">,</span>
                                               <span class="s2">&quot;initial_structure&quot;</span><span class="p">])</span>
        <span class="n">queen</span> <span class="o">=</span> <span class="n">BorgQueen</span><span class="p">(</span><span class="n">drone</span><span class="p">,</span> <span class="n">number_of_drones</span><span class="o">=</span><span class="n">ncpus</span><span class="p">)</span>
        <span class="n">queen</span><span class="o">.</span><span class="n">parallel_assimilate</span><span class="p">(</span><span class="n">rootdir</span><span class="p">)</span>

        <span class="n">structures</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">metadata</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">histories</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">queen</span><span class="o">.</span><span class="n">get_data</span><span class="p">():</span>
            <span class="n">structures</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">structure</span><span class="p">)</span>
            <span class="n">m</span> <span class="o">=</span> <span class="p">{</span>
                <span class="s2">&quot;_vasp&quot;</span><span class="p">:</span> <span class="p">{</span>
                    <span class="s2">&quot;parameters&quot;</span><span class="p">:</span> <span class="n">e</span><span class="o">.</span><span class="n">parameters</span><span class="p">,</span>
                    <span class="s2">&quot;final_energy&quot;</span><span class="p">:</span> <span class="n">e</span><span class="o">.</span><span class="n">energy</span><span class="p">,</span>
                    <span class="s2">&quot;final_energy_per_atom&quot;</span><span class="p">:</span> <span class="n">e</span><span class="o">.</span><span class="n">energy_per_atom</span><span class="p">,</span>
                    <span class="s2">&quot;initial_structure&quot;</span><span class="p">:</span> <span class="n">e</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="s2">&quot;initial_structure&quot;</span><span class="p">]</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>
                <span class="p">}</span>
            <span class="p">}</span>
            <span class="k">if</span> <span class="s2">&quot;history&quot;</span> <span class="ow">in</span> <span class="n">e</span><span class="o">.</span><span class="n">parameters</span><span class="p">:</span>
                <span class="n">histories</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">parameters</span><span class="p">[</span><span class="s2">&quot;history&quot;</span><span class="p">])</span>
            <span class="k">if</span> <span class="n">master_data</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
                <span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="n">master_data</span><span class="p">)</span>
            <span class="n">metadata</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">master_history</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">histories</span> <span class="o">=</span> <span class="n">master_history</span> <span class="o">*</span> <span class="nb">len</span><span class="p">(</span><span class="n">structures</span><span class="p">)</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">submit_structures</span><span class="p">(</span>
            <span class="n">structures</span><span class="p">,</span> <span class="n">authors</span><span class="p">,</span> <span class="n">projects</span><span class="o">=</span><span class="n">projects</span><span class="p">,</span> <span class="n">references</span><span class="o">=</span><span class="n">references</span><span class="p">,</span>
            <span class="n">remarks</span><span class="o">=</span><span class="n">remarks</span><span class="p">,</span> <span class="n">data</span><span class="o">=</span><span class="n">metadata</span><span class="p">,</span> <span class="n">histories</span><span class="o">=</span><span class="n">histories</span><span class="p">,</span>
            <span class="n">created_at</span><span class="o">=</span><span class="n">created_at</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_stability"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_stability">[docs]</a>    <span class="k">def</span> <span class="nf">get_stability</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">entries</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Returns the stability of all entries.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;entries&quot;</span><span class="p">:</span> <span class="n">json</span><span class="o">.</span><span class="n">dumps</span><span class="p">(</span><span class="n">entries</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyEncoder</span><span class="p">)}</span>
            <span class="n">response</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">session</span><span class="o">.</span><span class="n">post</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">{}</span><span class="s2">/phase_diagram/calculate_stability&quot;</span>
                                         <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">preamble</span><span class="p">),</span> <span class="n">data</span><span class="o">=</span><span class="n">payload</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">response</span><span class="o">.</span><span class="n">status_code</span> <span class="ow">in</span> <span class="p">[</span><span class="mi">200</span><span class="p">,</span> <span class="mi">400</span><span class="p">]:</span>
                <span class="n">resp</span> <span class="o">=</span> <span class="n">json</span><span class="o">.</span><span class="n">loads</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">,</span> <span class="bp">cls</span><span class="o">=</span><span class="n">MontyDecoder</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">resp</span><span class="p">[</span><span class="s2">&quot;valid_response&quot;</span><span class="p">]:</span>
                    <span class="k">if</span> <span class="n">resp</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;warning&quot;</span><span class="p">):</span>
                        <span class="n">warnings</span><span class="o">.</span><span class="n">warn</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;warning&quot;</span><span class="p">])</span>
                    <span class="k">return</span> <span class="n">resp</span><span class="p">[</span><span class="s2">&quot;response&quot;</span><span class="p">]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="n">resp</span><span class="p">[</span><span class="s2">&quot;error&quot;</span><span class="p">])</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="s2">&quot;REST error with status code </span><span class="si">{}</span><span class="s2"> and error </span><span class="si">{}</span><span class="s2">&quot;</span>
                              <span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">response</span><span class="o">.</span><span class="n">status_code</span><span class="p">,</span> <span class="n">response</span><span class="o">.</span><span class="n">text</span><span class="p">))</span>
        <span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">ex</span><span class="p">:</span>
            <span class="k">raise</span> <span class="n">MPRestError</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">ex</span><span class="p">))</span></div>

<div class="viewcode-block" id="MPRester.get_cohesive_energy"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_cohesive_energy">[docs]</a>    <span class="k">def</span> <span class="nf">get_cohesive_energy</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">,</span> <span class="n">per_atom</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the cohesive for a material (eV per formula unit). Cohesive energy</span>
<span class="sd">            is defined as the difference between the bulk energy and the sum of</span>
<span class="sd">            total DFT energy of isolated atoms for atom elements in the bulk.</span>
<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id, e.g. &#39;mp-123&#39;.</span>
<span class="sd">            per_atom (bool): Whether or not to return cohesive energy per atom</span>
<span class="sd">        Returns:</span>
<span class="sd">            Cohesive energy (eV).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">entry</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_entry_by_material_id</span><span class="p">(</span><span class="n">material_id</span><span class="p">)</span>
        <span class="n">ebulk</span> <span class="o">=</span> <span class="n">entry</span><span class="o">.</span><span class="n">energy</span> <span class="o">/</span> <span class="n">entry</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">get_integer_formula_and_factor</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
        <span class="n">comp_dict</span> <span class="o">=</span> <span class="n">entry</span><span class="o">.</span><span class="n">composition</span><span class="o">.</span><span class="n">reduced_composition</span><span class="o">.</span><span class="n">as_dict</span><span class="p">()</span>

        <span class="n">isolated_atom_e_sum</span><span class="p">,</span> <span class="n">n</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span>
        <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="n">comp_dict</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
            <span class="n">e</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/element/</span><span class="si">%s</span><span class="s2">/tasks/isolated_atom&quot;</span> <span class="o">%</span> <span class="p">(</span><span class="n">el</span><span class="p">),</span>
                                   <span class="n">mp_decode</span><span class="o">=</span><span class="kc">False</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span>
            <span class="n">isolated_atom_e_sum</span> <span class="o">+=</span> <span class="n">e</span><span class="p">[</span><span class="s1">&#39;output&#39;</span><span class="p">][</span><span class="s2">&quot;final_energy_per_atom&quot;</span><span class="p">]</span> <span class="o">*</span> <span class="n">comp_dict</span><span class="p">[</span><span class="n">el</span><span class="p">]</span>
            <span class="n">n</span> <span class="o">+=</span> <span class="n">comp_dict</span><span class="p">[</span><span class="n">el</span><span class="p">]</span>
        <span class="n">ecoh_per_formula</span> <span class="o">=</span> <span class="n">isolated_atom_e_sum</span> <span class="o">-</span> <span class="n">ebulk</span>
        <span class="k">return</span> <span class="n">ecoh_per_formula</span> <span class="o">/</span> <span class="n">n</span> <span class="k">if</span> <span class="n">per_atom</span> <span class="k">else</span> <span class="n">ecoh_per_formula</span></div>

<div class="viewcode-block" id="MPRester.get_reaction"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_reaction">[docs]</a>    <span class="k">def</span> <span class="nf">get_reaction</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reactants</span><span class="p">,</span> <span class="n">products</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets a reaction from the Materials Project.</span>

<span class="sd">        Args:</span>
<span class="sd">            reactants ([str]): List of formulas</span>
<span class="sd">            products ([str]): List of formulas</span>

<span class="sd">        Returns:</span>
<span class="sd">            rxn</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/reaction&quot;</span><span class="p">,</span>
                                  <span class="n">payload</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;reactants[]&quot;</span><span class="p">:</span> <span class="n">reactants</span><span class="p">,</span>
                                           <span class="s2">&quot;products[]&quot;</span><span class="p">:</span> <span class="n">products</span><span class="p">},</span> <span class="n">mp_decode</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_substrates"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_substrates">[docs]</a>    <span class="k">def</span> <span class="nf">get_substrates</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">,</span> <span class="n">number</span><span class="o">=</span><span class="mi">50</span><span class="p">,</span> <span class="n">orient</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Get a substrate list for a material id. The list is in order of</span>
<span class="sd">        increasing elastic energy if a elastic tensor is available for</span>
<span class="sd">        the material_id. Otherwise the list is in order of increasing</span>
<span class="sd">        matching area.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id, e.g. &#39;mp-123&#39;.</span>
<span class="sd">            orient (list) : substrate orientation to look for</span>
<span class="sd">            number (int) : number of substrates to return</span>
<span class="sd">                n=0 returns all available matches</span>
<span class="sd">        Returns:</span>
<span class="sd">            list of dicts with substrate matches</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">req</span> <span class="o">=</span> <span class="s2">&quot;/materials/</span><span class="si">{}</span><span class="s2">/substrates?n=</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span> <span class="n">number</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">orient</span><span class="p">:</span>
            <span class="n">req</span> <span class="o">+=</span> <span class="s2">&quot;&amp;orient=</span><span class="si">{}</span><span class="s2">&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="nb">str</span><span class="p">,</span> <span class="n">orient</span><span class="p">)))</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="n">req</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_all_substrates"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_all_substrates">[docs]</a>    <span class="k">def</span> <span class="nf">get_all_substrates</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets the list of all possible substrates considered in the</span>
<span class="sd">        Materials Project substrate database</span>

<span class="sd">        Returns:</span>
<span class="sd">            list of material_ids corresponding to possible substrates</span>
<span class="sd">        &quot;&quot;&quot;</span>

        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/materials/all_substrate_ids&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_surface_data"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_surface_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_surface_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">,</span> <span class="n">miller_index</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">inc_structures</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets surface data for a material. Useful for Wulff shapes.</span>

<span class="sd">        Reference for surface data:</span>

<span class="sd">        Tran, R., Xu, Z., Radhakrishnan, B., Winston, D., Sun, W., Persson, K.</span>
<span class="sd">        A., &amp; Ong, S. P. (2016). Data Descripter: Surface energies of elemental</span>
<span class="sd">        crystals. Scientific Data, 3(160080), 1–13.</span>
<span class="sd">        https://doi.org/10.1038/sdata.2016.80</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id, e.g. &#39;mp-123&#39;.</span>
<span class="sd">            miller_index (list of integer): The miller index of the surface.</span>
<span class="sd">            e.g., [3, 2, 1]. If miller_index is provided, only one dictionary</span>
<span class="sd">            of this specific plane will be returned.</span>
<span class="sd">            inc_structures (bool): Include final surface slab structures.</span>
<span class="sd">                These are unnecessary for Wulff shape construction.</span>
<span class="sd">        Returns:</span>
<span class="sd">            Surface data for material. Energies are given in SI units (J/m^2).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">req</span> <span class="o">=</span> <span class="s2">&quot;/materials/</span><span class="si">{}</span><span class="s2">/surfaces&quot;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">material_id</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">inc_structures</span><span class="p">:</span>
            <span class="n">req</span> <span class="o">+=</span> <span class="s2">&quot;?include_structures=true&quot;</span>

        <span class="k">if</span> <span class="n">miller_index</span><span class="p">:</span>
            <span class="n">surf_data_dict</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="n">req</span><span class="p">)</span>
            <span class="n">surf_list</span> <span class="o">=</span> <span class="n">surf_data_dict</span><span class="p">[</span><span class="s1">&#39;surfaces&#39;</span><span class="p">]</span>
            <span class="n">ucell</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_structure_by_material_id</span><span class="p">(</span><span class="n">material_id</span><span class="p">,</span>
                                                      <span class="n">conventional_unit_cell</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
            <span class="n">eq_indices</span> <span class="o">=</span> <span class="n">get_symmetrically_equivalent_miller_indices</span><span class="p">(</span><span class="n">ucell</span><span class="p">,</span> <span class="n">miller_index</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">one_surf</span> <span class="ow">in</span> <span class="n">surf_list</span><span class="p">:</span>
                <span class="k">if</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">one_surf</span><span class="p">[</span><span class="s1">&#39;miller_index&#39;</span><span class="p">])</span> <span class="ow">in</span> <span class="n">eq_indices</span><span class="p">:</span>
                    <span class="k">return</span> <span class="n">one_surf</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="n">req</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_wulff_shape"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_wulff_shape">[docs]</a>    <span class="k">def</span> <span class="nf">get_wulff_shape</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Constructs a Wulff shape for a material.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id, e.g. &#39;mp-123&#39;.</span>
<span class="sd">        Returns:</span>
<span class="sd">            pymatgen.analysis.wulff.WulffShape</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="kn">from</span> <span class="nn">pymatgen.symmetry.analyzer</span> <span class="kn">import</span> <span class="n">SpacegroupAnalyzer</span>
        <span class="kn">from</span> <span class="nn">pymatgen.analysis.wulff</span> <span class="kn">import</span> <span class="n">WulffShape</span>

        <span class="n">structure</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_structure_by_material_id</span><span class="p">(</span><span class="n">material_id</span><span class="p">)</span>
        <span class="n">surfaces</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_surface_data</span><span class="p">(</span><span class="n">material_id</span><span class="p">)[</span><span class="s2">&quot;surfaces&quot;</span><span class="p">]</span>
        <span class="n">lattice</span> <span class="o">=</span> <span class="p">(</span><span class="n">SpacegroupAnalyzer</span><span class="p">(</span><span class="n">structure</span><span class="p">)</span>
                   <span class="o">.</span><span class="n">get_conventional_standard_structure</span><span class="p">()</span><span class="o">.</span><span class="n">lattice</span><span class="p">)</span>
        <span class="n">miller_energy_map</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="k">for</span> <span class="n">surf</span> <span class="ow">in</span> <span class="n">surfaces</span><span class="p">:</span>
            <span class="n">miller</span> <span class="o">=</span> <span class="nb">tuple</span><span class="p">(</span><span class="n">surf</span><span class="p">[</span><span class="s2">&quot;miller_index&quot;</span><span class="p">])</span>
            <span class="c1"># Prefer reconstructed surfaces, which have lower surface energies.</span>
            <span class="k">if</span> <span class="p">(</span><span class="n">miller</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">miller_energy_map</span><span class="p">)</span> <span class="ow">or</span> <span class="n">surf</span><span class="p">[</span><span class="s2">&quot;is_reconstructed&quot;</span><span class="p">]:</span>
                <span class="n">miller_energy_map</span><span class="p">[</span><span class="n">miller</span><span class="p">]</span> <span class="o">=</span> <span class="n">surf</span><span class="p">[</span><span class="s2">&quot;surface_energy&quot;</span><span class="p">]</span>
        <span class="n">millers</span><span class="p">,</span> <span class="n">energies</span> <span class="o">=</span> <span class="nb">zip</span><span class="p">(</span><span class="o">*</span><span class="n">miller_energy_map</span><span class="o">.</span><span class="n">items</span><span class="p">())</span>
        <span class="k">return</span> <span class="n">WulffShape</span><span class="p">(</span><span class="n">lattice</span><span class="p">,</span> <span class="n">millers</span><span class="p">,</span> <span class="n">energies</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_gb_data"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_gb_data">[docs]</a>    <span class="k">def</span> <span class="nf">get_gb_data</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_id</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">pretty_formula</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">chemsys</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">sigma</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">gb_plane</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                    <span class="n">rotation_axis</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">include_work_of_separation</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets grain boundary data for a material.</span>

<span class="sd">        Args:</span>
<span class="sd">            material_id (str): Materials Project material_id, e.g., &#39;mp-129&#39;.</span>
<span class="sd">            pretty_formula (str): The formula of metals. e.g., &#39;Fe&#39;</span>
<span class="sd">            sigma(int): The sigma value of a certain type of grain boundary</span>
<span class="sd">            gb_plane(list of integer): The Miller index of grain</span>
<span class="sd">            boundary plane. e.g., [1, 1, 1]</span>
<span class="sd">            rotation_axis(list of integer): The Miller index of rotation</span>
<span class="sd">            axis. e.g., [1, 0, 0], [1, 1, 0], and [1, 1, 1]</span>
<span class="sd">            Sigma value is determined by the combination of rotation axis and</span>
<span class="sd">            rotation angle. The five degrees of freedom (DOF) of one grain boundary</span>
<span class="sd">            include: rotation axis (2 DOFs), rotation angle (1 DOF), and grain</span>
<span class="sd">            boundary plane (2 DOFs).</span>
<span class="sd">            include_work_of_separation (bool): whether to include the work of separation</span>
<span class="sd">            (in unit of (J/m^2)). If you want to query the work of separation, please</span>
<span class="sd">            specify the material_id.</span>


<span class="sd">        Returns:</span>
<span class="sd">            A list of grain boundaries that satisfy the query conditions (sigma, gb_plane).</span>
<span class="sd">            Energies are given in SI units (J/m^2).</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="n">gb_plane</span><span class="p">:</span>
            <span class="n">gb_plane</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">gb_plane</span><span class="p">])</span>
        <span class="k">if</span> <span class="n">rotation_axis</span><span class="p">:</span>
            <span class="n">rotation_axis</span> <span class="o">=</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">)</span> <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="n">rotation_axis</span><span class="p">])</span>

        <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;material_id&quot;</span><span class="p">:</span> <span class="n">material_id</span><span class="p">,</span>
                   <span class="s2">&quot;pretty_formula&quot;</span><span class="p">:</span> <span class="n">pretty_formula</span><span class="p">,</span>
                   <span class="s2">&quot;chemsys&quot;</span><span class="p">:</span> <span class="n">chemsys</span><span class="p">,</span>
                   <span class="s2">&quot;sigma&quot;</span><span class="p">:</span> <span class="n">sigma</span><span class="p">,</span>
                   <span class="s2">&quot;gb_plane&quot;</span><span class="p">:</span> <span class="n">gb_plane</span><span class="p">,</span>
                   <span class="s2">&quot;rotation_axis&quot;</span><span class="p">:</span> <span class="n">rotation_axis</span><span class="p">}</span>

        <span class="k">if</span> <span class="n">include_work_of_separation</span> <span class="ow">and</span> <span class="n">material_id</span><span class="p">:</span>
            <span class="n">list_of_gbs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/grain_boundaries&quot;</span><span class="p">,</span>
                                             <span class="n">payload</span><span class="o">=</span><span class="n">payload</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">i</span><span class="p">,</span> <span class="n">gb_dict</span> <span class="ow">in</span> <span class="nb">enumerate</span><span class="p">(</span><span class="n">list_of_gbs</span><span class="p">):</span>
                <span class="n">gb_energy</span> <span class="o">=</span> <span class="n">gb_dict</span><span class="p">[</span><span class="s1">&#39;gb_energy&#39;</span><span class="p">]</span>
                <span class="n">gb_plane_int</span> <span class="o">=</span> <span class="n">gb_dict</span><span class="p">[</span><span class="s1">&#39;gb_plane&#39;</span><span class="p">]</span>
                <span class="n">surface_energy</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_surface_data</span><span class="p">(</span><span class="n">material_id</span><span class="o">=</span><span class="n">material_id</span><span class="p">,</span>
                                                       <span class="n">miller_index</span><span class="o">=</span><span class="n">gb_plane_int</span><span class="p">)[</span><span class="s1">&#39;surface_energy&#39;</span><span class="p">]</span>
                <span class="n">wsep</span> <span class="o">=</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">surface_energy</span> <span class="o">-</span> <span class="n">gb_energy</span>  <span class="c1"># calculate the work of separation</span>
                <span class="n">gb_dict</span><span class="p">[</span><span class="s1">&#39;work_of_separation&#39;</span><span class="p">]</span> <span class="o">=</span> <span class="n">wsep</span>
            <span class="k">return</span> <span class="n">list_of_gbs</span>

        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/grain_boundaries&quot;</span><span class="p">,</span>
                                      <span class="n">payload</span><span class="o">=</span><span class="n">payload</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_interface_reactions"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_interface_reactions">[docs]</a>    <span class="k">def</span> <span class="nf">get_interface_reactions</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">reactant1</span><span class="p">,</span> <span class="n">reactant2</span><span class="p">,</span>
                                <span class="n">open_el</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">relative_mu</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                                <span class="n">use_hull_energy</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Gets critical reactions between two reactants.</span>

<span class="sd">        Get critical reactions (&quot;kinks&quot; in the mixing ratio where</span>
<span class="sd">        reaction products change) between two reactants. See the</span>
<span class="sd">        `pymatgen.analysis.interface_reactions` module for more info.</span>

<span class="sd">        Args:</span>
<span class="sd">            reactant1 (str): Chemical formula for reactant</span>
<span class="sd">            reactant2 (str): Chemical formula for reactant</span>
<span class="sd">            open_el (str): Element in reservoir available to system</span>
<span class="sd">            relative_mu (float): Relative chemical potential of element in</span>
<span class="sd">                reservoir with respect to pure substance. Must be non-positive.</span>
<span class="sd">            use_hull_energy (bool): Whether to use the convex hull energy for a</span>
<span class="sd">            given composition for the reaction energy calculation. If false,</span>
<span class="sd">            the energy of the ground state structure will be preferred; if a</span>
<span class="sd">            ground state can not be found for a composition, the convex hull</span>
<span class="sd">            energy will be used with a warning message.</span>

<span class="sd">        Returns:</span>
<span class="sd">            list: list of dicts of form {ratio,energy,rxn} where `ratio` is the</span>
<span class="sd">                reactant mixing ratio, `energy` is the reaction energy</span>
<span class="sd">                in eV/atom, and `rxn` is a</span>
<span class="sd">                `pymatgen.analysis.reaction_calculator.Reaction`.</span>

<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">payload</span> <span class="o">=</span> <span class="p">{</span><span class="s2">&quot;reactants&quot;</span><span class="p">:</span> <span class="s2">&quot; &quot;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="n">reactant1</span><span class="p">,</span> <span class="n">reactant2</span><span class="p">]),</span>
                   <span class="s2">&quot;open_el&quot;</span><span class="p">:</span> <span class="n">open_el</span><span class="p">,</span>
                   <span class="s2">&quot;relative_mu&quot;</span><span class="p">:</span> <span class="n">relative_mu</span><span class="p">,</span>
                   <span class="s2">&quot;use_hull_energy&quot;</span><span class="p">:</span> <span class="n">use_hull_energy</span><span class="p">}</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">_make_request</span><span class="p">(</span><span class="s2">&quot;/interface_reactions&quot;</span><span class="p">,</span>
                                  <span class="n">payload</span><span class="o">=</span><span class="n">payload</span><span class="p">,</span> <span class="n">method</span><span class="o">=</span><span class="s2">&quot;POST&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="MPRester.get_download_info"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.get_download_info">[docs]</a>    <span class="k">def</span> <span class="nf">get_download_info</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">material_ids</span><span class="p">,</span> <span class="n">task_types</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">file_patterns</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        get a list of URLs to retrieve raw VASP output files from the NoMaD repository</span>

<span class="sd">        Args:</span>
<span class="sd">            material_ids (list): list of material identifiers (mp-id&#39;s)</span>
<span class="sd">            task_types (list): list of task types to include in download (see TaskType Enum class)</span>
<span class="sd">            file_patterns (list): list of wildcard file names to include for each task</span>

<span class="sd">        Returns:</span>
<span class="sd">            a tuple of 1) a dictionary mapping material_ids to task_ids and</span>
<span class="sd">            task_types, and 2) a list of URLs to download zip archives from</span>
<span class="sd">            NoMaD repository. Each zip archive will contain a manifest.json with</span>
<span class="sd">            metadata info, e.g. the task/external_ids that belong to a directory</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="c1"># task_id&#39;s correspond to NoMaD external_id&#39;s</span>
        <span class="n">task_types</span> <span class="o">=</span> <span class="p">[</span><span class="n">t</span><span class="o">.</span><span class="n">value</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">task_types</span> <span class="k">if</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">t</span><span class="p">,</span> <span class="n">TaskType</span><span class="p">)]</span> <span class="k">if</span> <span class="n">task_types</span> <span class="k">else</span> <span class="p">[]</span>

        <span class="n">meta</span> <span class="o">=</span> <span class="n">defaultdict</span><span class="p">(</span><span class="nb">list</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">doc</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">query</span><span class="p">({</span><span class="s1">&#39;material_id&#39;</span><span class="p">:</span> <span class="p">{</span><span class="s1">&#39;$in&#39;</span><span class="p">:</span> <span class="n">material_ids</span><span class="p">}},</span>
                              <span class="p">[</span><span class="s1">&#39;material_id&#39;</span><span class="p">,</span> <span class="s1">&#39;blessed_tasks&#39;</span><span class="p">]):</span>

            <span class="k">for</span> <span class="n">task_type</span><span class="p">,</span> <span class="n">task_id</span> <span class="ow">in</span> <span class="n">doc</span><span class="p">[</span><span class="s1">&#39;blessed_tasks&#39;</span><span class="p">]</span><span class="o">.</span><span class="n">items</span><span class="p">():</span>
                <span class="k">if</span> <span class="n">task_types</span> <span class="ow">and</span> <span class="n">task_type</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">task_types</span><span class="p">:</span>
                    <span class="k">continue</span>
                <span class="n">meta</span><span class="p">[</span><span class="n">doc</span><span class="p">[</span><span class="s2">&quot;material_id&quot;</span><span class="p">]]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span>
                    <span class="p">{</span><span class="s1">&#39;task_id&#39;</span><span class="p">:</span> <span class="n">task_id</span><span class="p">,</span> <span class="s1">&#39;task_type&#39;</span><span class="p">:</span> <span class="n">task_type</span><span class="p">}</span>
                <span class="p">)</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="n">meta</span><span class="p">:</span>
            <span class="k">raise</span> <span class="ne">ValueError</span><span class="p">(</span><span class="s1">&#39;No tasks found.&#39;</span><span class="p">)</span>

        <span class="c1"># return a list of URLs for NoMaD Downloads containing the list of files</span>
        <span class="c1"># for every external_id in `task_ids`</span>
        <span class="n">prefix</span> <span class="o">=</span> <span class="s1">&#39;http://labdev-nomad.esc.rzg.mpg.de/fairdi/nomad/mp/api/raw/query?&#39;</span>
        <span class="k">if</span> <span class="n">file_patterns</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">for</span> <span class="n">file_pattern</span> <span class="ow">in</span> <span class="n">file_patterns</span><span class="p">:</span>
                <span class="n">prefix</span> <span class="o">+=</span> <span class="sa">f</span><span class="s1">&#39;file_pattern=</span><span class="si">{</span><span class="n">file_pattern</span><span class="si">}</span><span class="s1">&amp;&#39;</span>
        <span class="n">prefix</span> <span class="o">+=</span> <span class="s1">&#39;external_id=&#39;</span>

        <span class="c1"># NOTE: IE has 2kb URL char limit</span>
        <span class="n">nmax</span> <span class="o">=</span> <span class="nb">int</span><span class="p">((</span><span class="mi">2000</span> <span class="o">-</span> <span class="nb">len</span><span class="p">(</span><span class="n">prefix</span><span class="p">))</span> <span class="o">/</span> <span class="mi">11</span><span class="p">)</span>  <span class="c1"># mp-&lt;7-digit&gt; + , = 11</span>
        <span class="n">task_ids</span> <span class="o">=</span> <span class="p">[</span><span class="n">t</span><span class="p">[</span><span class="s1">&#39;task_id&#39;</span><span class="p">]</span> <span class="k">for</span> <span class="n">tl</span> <span class="ow">in</span> <span class="n">meta</span><span class="o">.</span><span class="n">values</span><span class="p">()</span> <span class="k">for</span> <span class="n">t</span> <span class="ow">in</span> <span class="n">tl</span><span class="p">]</span>
        <span class="n">chunks</span> <span class="o">=</span> <span class="n">get_chunks</span><span class="p">(</span><span class="n">task_ids</span><span class="p">,</span> <span class="n">size</span><span class="o">=</span><span class="n">nmax</span><span class="p">)</span>
        <span class="n">urls</span> <span class="o">=</span> <span class="p">[</span><span class="n">prefix</span> <span class="o">+</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">tids</span><span class="p">)</span> <span class="k">for</span> <span class="n">tids</span> <span class="ow">in</span> <span class="n">chunks</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">meta</span><span class="p">,</span> <span class="n">urls</span></div>

<div class="viewcode-block" id="MPRester.parse_criteria"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRester.parse_criteria">[docs]</a>    <span class="nd">@staticmethod</span>
    <span class="k">def</span> <span class="nf">parse_criteria</span><span class="p">(</span><span class="n">criteria_string</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Parses a powerful and simple string criteria and generates a proper</span>
<span class="sd">        mongo syntax criteria.</span>

<span class="sd">        Args:</span>
<span class="sd">            criteria_string (str): A string representing a search criteria.</span>
<span class="sd">                Also supports wild cards. E.g.,</span>
<span class="sd">                something like &quot;*2O&quot; gets converted to</span>
<span class="sd">                {&#39;pretty_formula&#39;: {&#39;$in&#39;: [u&#39;B2O&#39;, u&#39;Xe2O&#39;, u&quot;Li2O&quot;, ...]}}</span>

<span class="sd">                Other syntax examples:</span>
<span class="sd">                    mp-1234: Interpreted as a Materials ID.</span>
<span class="sd">                    Fe2O3 or *2O3: Interpreted as reduced formulas.</span>
<span class="sd">                    Li-Fe-O or *-Fe-O: Interpreted as chemical systems.</span>

<span class="sd">                You can mix and match with spaces, which are interpreted as</span>
<span class="sd">                &quot;OR&quot;. E.g., &quot;mp-1234 FeO&quot; means query for all compounds with</span>
<span class="sd">                reduced formula FeO or with materials_id mp-1234.</span>

<span class="sd">        Returns:</span>
<span class="sd">            A mongo query dict.</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">toks</span> <span class="o">=</span> <span class="n">criteria_string</span><span class="o">.</span><span class="n">split</span><span class="p">()</span>

        <span class="k">def</span> <span class="nf">parse_sym</span><span class="p">(</span><span class="n">sym</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">sym</span> <span class="o">==</span> <span class="s2">&quot;*&quot;</span><span class="p">:</span>
                <span class="k">return</span> <span class="p">[</span><span class="n">el</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">el</span> <span class="ow">in</span> <span class="n">Element</span><span class="p">]</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\{(.*)\}&quot;</span><span class="p">,</span> <span class="n">sym</span><span class="p">)</span>
                <span class="k">if</span> <span class="n">m</span><span class="p">:</span>
                    <span class="k">return</span> <span class="p">[</span><span class="n">s</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;,&quot;</span><span class="p">)]</span>
                <span class="k">else</span><span class="p">:</span>
                    <span class="k">return</span> <span class="p">[</span><span class="n">sym</span><span class="p">]</span>

        <span class="k">def</span> <span class="nf">parse_tok</span><span class="p">(</span><span class="n">t</span><span class="p">):</span>
            <span class="k">if</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;\w+-\d+&quot;</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
                <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;task_id&quot;</span><span class="p">:</span> <span class="n">t</span><span class="p">}</span>
            <span class="k">elif</span> <span class="s2">&quot;-&quot;</span> <span class="ow">in</span> <span class="n">t</span><span class="p">:</span>
                <span class="n">elements</span> <span class="o">=</span> <span class="p">[</span><span class="n">parse_sym</span><span class="p">(</span><span class="n">sym</span><span class="p">)</span> <span class="k">for</span> <span class="n">sym</span> <span class="ow">in</span> <span class="n">t</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">&quot;-&quot;</span><span class="p">)]</span>
                <span class="n">chemsyss</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">cs</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">elements</span><span class="p">):</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">cs</span><span class="p">))</span> <span class="o">==</span> <span class="nb">len</span><span class="p">(</span><span class="n">cs</span><span class="p">):</span>
                        <span class="c1"># Check for valid symbols</span>
                        <span class="n">cs</span> <span class="o">=</span> <span class="p">[</span><span class="n">Element</span><span class="p">(</span><span class="n">s</span><span class="p">)</span><span class="o">.</span><span class="n">symbol</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">cs</span><span class="p">]</span>
                        <span class="n">chemsyss</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="s2">&quot;-&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="nb">sorted</span><span class="p">(</span><span class="n">cs</span><span class="p">)))</span>
                <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;chemsys&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;$in&quot;</span><span class="p">:</span> <span class="n">chemsyss</span><span class="p">}}</span>
            <span class="k">else</span><span class="p">:</span>
                <span class="n">all_formulas</span> <span class="o">=</span> <span class="nb">set</span><span class="p">()</span>
                <span class="n">explicit_els</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="n">wild_card_els</span> <span class="o">=</span> <span class="p">[]</span>
                <span class="k">for</span> <span class="n">sym</span> <span class="ow">in</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span>
                        <span class="sa">r</span><span class="s2">&quot;(\*[\.\d]*|\{.*\}[\.\d]*|[A-Z][a-z]*)[\.\d]*&quot;</span><span class="p">,</span> <span class="n">t</span><span class="p">):</span>
                    <span class="k">if</span> <span class="p">(</span><span class="s2">&quot;*&quot;</span> <span class="ow">in</span> <span class="n">sym</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="s2">&quot;{&quot;</span> <span class="ow">in</span> <span class="n">sym</span><span class="p">):</span>
                        <span class="n">wild_card_els</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">sym</span><span class="p">)</span>
                    <span class="k">else</span><span class="p">:</span>
                        <span class="n">m</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">match</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;([A-Z][a-z]*)[\.\d]*&quot;</span><span class="p">,</span> <span class="n">sym</span><span class="p">)</span>
                        <span class="n">explicit_els</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">group</span><span class="p">(</span><span class="mi">1</span><span class="p">))</span>
                <span class="n">nelements</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="n">wild_card_els</span><span class="p">)</span> <span class="o">+</span> <span class="nb">len</span><span class="p">(</span><span class="nb">set</span><span class="p">(</span><span class="n">explicit_els</span><span class="p">))</span>
                <span class="n">parts</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="sa">r</span><span class="s2">&quot;(\*|\{.*\})&quot;</span><span class="p">,</span> <span class="n">t</span><span class="p">)</span>
                <span class="n">parts</span> <span class="o">=</span> <span class="p">[</span><span class="n">parse_sym</span><span class="p">(</span><span class="n">s</span><span class="p">)</span> <span class="k">for</span> <span class="n">s</span> <span class="ow">in</span> <span class="n">parts</span> <span class="k">if</span> <span class="n">s</span> <span class="o">!=</span> <span class="s2">&quot;&quot;</span><span class="p">]</span>
                <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">itertools</span><span class="o">.</span><span class="n">product</span><span class="p">(</span><span class="o">*</span><span class="n">parts</span><span class="p">):</span>
                    <span class="n">c</span> <span class="o">=</span> <span class="n">Composition</span><span class="p">(</span><span class="s2">&quot;&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">f</span><span class="p">))</span>
                    <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">c</span><span class="p">)</span> <span class="o">==</span> <span class="n">nelements</span><span class="p">:</span>
                        <span class="c1"># Check for valid Elements in keys.</span>
                        <span class="k">for</span> <span class="n">e</span> <span class="ow">in</span> <span class="n">c</span><span class="o">.</span><span class="n">keys</span><span class="p">():</span>
                            <span class="n">Element</span><span class="p">(</span><span class="n">e</span><span class="o">.</span><span class="n">symbol</span><span class="p">)</span>
                        <span class="n">all_formulas</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">c</span><span class="o">.</span><span class="n">reduced_formula</span><span class="p">)</span>
                <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;pretty_formula&quot;</span><span class="p">:</span> <span class="p">{</span><span class="s2">&quot;$in&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="n">all_formulas</span><span class="p">)}}</span>

        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">toks</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">parse_tok</span><span class="p">(</span><span class="n">toks</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="p">{</span><span class="s2">&quot;$or&quot;</span><span class="p">:</span> <span class="nb">list</span><span class="p">(</span><span class="nb">map</span><span class="p">(</span><span class="n">parse_tok</span><span class="p">,</span> <span class="n">toks</span><span class="p">))}</span></div></div>


<div class="viewcode-block" id="MPRestError"><a class="viewcode-back" href="../../../pymatgen.ext.matproj.html#pymatgen.ext.matproj.MPRestError">[docs]</a><span class="k">class</span> <span class="nc">MPRestError</span><span class="p">(</span><span class="ne">Exception</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Exception class for MPRestAdaptor.</span>
<span class="sd">    Raised when the query has problems, e.g., bad query format.</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">pass</span></div>
</pre></div>

            <div class="clearer"></div>
          </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">pymatgen 2020.7.3 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >Module code</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../../pymatgen.html" >pymatgen</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="">pymatgen.ext.matproj</a></li> 
      </ul>
    </div>

    <div class="footer" role="contentinfo">
        &#169; Copyright 2011, Pymatgen Development Team.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.1.2.
    </div>
<div class="footer">This page uses <a href="http://analytics.google.com/">
Google Analytics</a> to collect statistics. You can disable it by blocking
the JavaScript coming from www.google-analytics.com.
<script type="text/javascript">
  (function() {
    var ga = document.createElement('script');
    ga.src = ('https:' == document.location.protocol ?
              'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    ga.setAttribute('async', 'true');
    document.documentElement.firstChild.appendChild(ga);
  })();
</script>
</div>

  </body>
</html>